Search code examples
flutterfloating-action-button

red line under closing tags flutter


Im trying to set up a TO do list and i keep getting these red lines under my closing tags

So i'm making a TO do list and have everything basicly set up but the closing tags all the way at the bottom have red lines under them

This is my first time using stack so forgive me if im an idiot

Ive tried switching them

import 'package:flutter/material.dart';

    void main() {
      runApp(new MyApp(
        title: new Text("My App"), someText: new Text("Some Text..."),));
    }

      class MyApp extends StatefulWidget {
        MyApp({this.title, this.someText});

        final Widget title, someText;

        @override
        MyAppState createState() => new MyAppState();
      }
      class MyAppState extends State<MyApp> {
       TextEditingController eCtrl = new TextEditingController();
       bool showDialog = false;
       List<bool> textChkBox = [];
       List<String> textlist = [];
       Widget build (BuildContext ctxt) {
         return new MaterialApp (
             home: new Scaffold (
               appBar: new AppBar(
                 title: widget.title,
                 actions: <Widget>[
                   new IconButton(
                       icon: new Icon (Icons.add_comment),
                       onPressed: () {
                         setState(() {
                           showDialog = true;
                         });
                       }
                   ),
                   new IconButton(
                       icon: new Icon (Icons.remove),
                       onPressed: () {
                         setState(() {});
                       }
                   ),
                 ],
               ),
               body: new Column(
                 children: <Widget>[
                   new Text("Hello Flutter"),
                   showDialog == true ?
                   new AlertDialog(
                     title: new Text("Alert Dialog"),
                     content: new TextField
                       (
                       controller: eCtrl,
                       decoration: new InputDecoration.collapsed(
                           hintText: "ADD XYZ"),
                       maxLines: 3,
                       onSubmitted: (String text) {

                       },
                     ),
                     actions: <Widget>[
                       new FlatButton (
                           onPressed: () {
                             setState(() {
                               showDialog = false;
                               textlist.add(eCtrl.text);
                               textChkBox.add(false);
                               eCtrl.clear();
                             });
                           },
                           child: new Text("OK")
                       )
                     ],
                   ) : new Text(""),

                   new Flexible(
                       child: new ListView.builder(
                           itemCount: textlist.length,
                           itemBuilder: (BuildContext ctxt, int index) {
                             return new Row(
                                 children: <Widget>[
                                   new Checkbox(
                                     value: textChkBox[index],
                                     onChanged: (bool newValue) {
                                       textChkBox[index] = newValue;
                                       setState(() {});
                                     },
                                   ),
                                   new Text(textlist[index])
                                 ]

                             );
                         }
                       )
                   )
                 ],
         )
       }

Solution

  • You are missing a couple of brackets/parenthesis.

    Replace your last line by ),);}} and you will be good to go.

    Your code should be:

    import 'package:flutter/material.dart';
    
    void main() {
      runApp(new MyApp(
        title: new Text("My App"),
        someText: new Text("Some Text..."),
      ));
    }
    
    class MyApp extends StatefulWidget {
      MyApp({this.title, this.someText});
    
      final Widget title, someText;
    
      @override
      MyAppState createState() => new MyAppState();
    }
    
    class MyAppState extends State<MyApp> {
      TextEditingController eCtrl = new TextEditingController();
      bool showDialog = false;
      List<bool> textChkBox = [];
      List<String> textlist = [];
      Widget build(BuildContext ctxt) {
        return new MaterialApp(
          home: new Scaffold(
            appBar: new AppBar(
              title: widget.title,
              actions: <Widget>[
                new IconButton(
                    icon: new Icon(Icons.add_comment),
                    onPressed: () {
                      setState(() {
                        showDialog = true;
                      });
                    }),
                new IconButton(
                    icon: new Icon(Icons.remove),
                    onPressed: () {
                      setState(() {});
                    }),
              ],
            ),
            body: new Column(
              children: <Widget>[
                new Text("Hello Flutter"),
                showDialog == true
                    ? new AlertDialog(
                        title: new Text("Alert Dialog"),
                        content: new TextField(
                          controller: eCtrl,
                          decoration: new InputDecoration.collapsed(hintText: "ADD XYZ"),
                          maxLines: 3,
                          onSubmitted: (String text) {},
                        ),
                        actions: <Widget>[
                          new FlatButton(
                              onPressed: () {
                                setState(() {
                                  showDialog = false;
                                  textlist.add(eCtrl.text);
                                  textChkBox.add(false);
                                  eCtrl.clear();
                                });
                              },
                              child: new Text("OK"))
                        ],
                      )
                    : new Text(""),
                new Flexible(
                    child: new ListView.builder(
                        itemCount: textlist.length,
                        itemBuilder: (BuildContext ctxt, int index) {
                          return new Row(children: <Widget>[
                            new Checkbox(
                              value: textChkBox[index],
                              onChanged: (bool newValue) {
                                textChkBox[index] = newValue;
                                setState(() {});
                              },
                            ),
                            new Text(textlist[index])
                          ]);
                        }))
              ],
            ),
          ),
        );
      }
    }
    

    All those brackets, square brackets and parenthesis can be a bit confusing when you start.

    If you are using VSCode, make sure you are using this extension: https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer-2

    It well help you identify where your blocks of code start and end by colouring your brackets/parenthesis.

    Have fun coding in Flutter! :)