关闭标签下的红线飘动

red line under closing tags flutter

我正在尝试设置一个待办事项列表,但我总是在结束标签下看到这些红线

所以我正在制作一个待办事项列表并基本设置好所有内容,但底部的结束标记下面有红线

这是我第一次使用堆栈,如果我是白痴,请原谅我

我试过切换它们

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])
                                 ]

                             );
                         }
                       )
                   )
                 ],
         )
       }

您缺少几个 brackets/parenthesis。

将最后一行替换为 ),);}},您就可以开始了。

您的代码应该是:

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])
                      ]);
                    }))
          ],
        ),
      ),
    );
  }
}

所有这些括号、方括号和圆括号在您开始时可能会有点混乱。

如果您使用的是 VSCode,请确保您使用的是此扩展程序:https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer-2

它通过给 brackets/parenthesis 上色来很好地帮助您识别代码块的开始和结束位置。

祝您在 Flutter 中尽情编码! :)