【问题标题】:OverflowBar's children must not contain any null values, but a null value was found at index 1OverflowBar 的子项不得包含任何空值,但在索引 1 处找到空值
【发布时间】:2021-10-29 23:36:27
【问题描述】:

您好,我正在使用 Flutter 更新移动应用程序构建。但是当我运行此应用程序时出现此错误
OverflowBar 的子项不得包含任何空值,但在索引 1 处发现空值强>

final rep = await showDialog(
           context: context,
           builder: (BuildContext context) {
             return AlertDialog(
               title: Text("Entrez votre constat : "),
               content: new TextField(
                 keyboardType: TextInputType.multiline,
                 maxLines: 5,
                 controller: _constate,
               ),
               actions: <Widget>[
                 FlatButton(
                   child: Text("Enregistrer"),
                   onPressed: () {
                     Navigator.pop(context, _constate.text);
                   },
                 ),
                 c!=null?FlatButton(
                   child: Text("Supprimer"),
                   onPressed: () {
                     _deleteConstat(c, q);
                     Navigator.pop(context, null);
                   },
                 ):null,
                 FlatButton(
                   child: Text("Anuller"),
                   onPressed: () {
                     Navigator.pop(context, null);
                   },
                 ),
               ],
               elevation: 23,
             );
           }); ```

【问题讨论】:

    标签: flutter flutter-alertdialog


    【解决方案1】:
      c!=null?FlatButton(
                       child: Text("Supprimer"),
                       onPressed: () {
                         _deleteConstat(c, q);
                         Navigator.pop(context, null);
                       },
                     ):Container(),
    

    【讨论】:

      【解决方案2】:

      此代码导致错误

        c!=null?FlatButton(
                         child: Text("Supprimer"),
                         onPressed: () {
                           _deleteConstat(c, q);
                           Navigator.pop(context, null);
                         },
                       ):null,
      

      优先使用SizedBox 代替null

      【讨论】:

      • 谢谢。我在哪个地方放了空格而不是 null
      • 而不是: null,你可以使用: SizedBox()
      猜你喜欢
      • 2020-12-02
      • 1970-01-01
      • 2020-12-08
      • 2021-06-10
      • 2022-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多