【问题标题】:red line under closing tags flutter结束标签下的红线颤动
【发布时间】:2019-08-04 13:30:30
【问题描述】:

我正在尝试设置一个待办事项列表,但我的结束标签下不断出现这些红线

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

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

我尝试过切换它们

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

                             );
                         }
                       )
                   )
                 ],
         )
       }

【问题讨论】:

    标签: flutter floating-action-button


    【解决方案1】:

    您缺少几个括号/括号。

    ),);}} 替换你的最后一行,你就可以开始了。

    你的代码应该是:

    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

    它可以很好地帮助您通过为括号/括号着色来确定代码块的开始和结束位置。

    在 Flutter 中玩得开心! :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-22
      • 2021-09-01
      相关资源
      最近更新 更多