【问题标题】:Failed assertion: line 235 pos 15: 'data != null': is not true断言失败:第 235 行 pos 15:“数据!= null”:不正确
【发布时间】:2019-05-24 10:07:55
【问题描述】:

尝试在标签栏中添加小部件时出现此错误。请检查以下代码

return Scaffold(
      appBar: new AppBar(
        bottom: PreferredSize(
            child: _tabBar,
            preferredSize: Size.fromHeight(_tabBar.preferredSize.height - 50),
        ),
      ),

      body:  new TabBarView(
        controller: _tabController,
        children: <Widget>[
          new PicMee(),
          new PicMee()
        ],
      ),
    );

对于 Picmee 文件:

class PicMee extends StatefulWidget{
  @override
  _PicMeeState createState() => new _PicMeeState();
}

    class _PicMeeState extends State<PicMee>{
      @override
      Widget build(BuildContext context) {
        // TODO: implement build
        return new Scaffold(
          body: new ListView.builder(
              itemCount: 20,
              itemBuilder: (BuildContext context, int index){
                return new CustomWidget(date: null, content: null, trailingIconOne: null, trailingIconTwo: null)
              }

    //          https://stackoverflow.com/questions/47233209/flutter-group-listviews-with-separator?rq=1
          ),
        );
      }
    }

    class CustomWidget extends StatelessWidget {
      String date;
      String content;

      Icon trailingIconOne;

      Icon trailingIconTwo;

      CustomWidget(
          {@required this.date, @required this.content, @required this.trailingIconOne, @required this.trailingIconTwo});

      @override
      Widget build(BuildContext context) {
        return new Container(
          decoration: new BoxDecoration(
              border: new Border.all(color: Colors.grey[500])
          ),
          child: new Column(
            children: <Widget>[
              new Container (child: new Text(date), color: Colors.yellow[200],),
              new Container(height: 15.0,),
              new Text(content),
              new Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: <Widget>[
                  new IconButton(icon: trailingIconOne, onPressed: () {}),
                  new Container(width: 10.0,),
                  new IconButton(icon: trailingIconTwo, onPressed: () {})
                ],
              )
            ],
          ),
        );
      }
    }

我收到此错误:

flutter:又抛出了一个异常:

'package:flutter/src/widgets/text.dart':断言失败:第 235 行 pos 15: 'data != null': 不正确。

【问题讨论】:

  • 你能告诉我们 PicMee 的代码吗?
  • 我已经添加了代码。

标签: dart flutter


【解决方案1】:

替换这一行:

return new CustomWidget(date: null, content: null, trailingIconOne: null, trailingIconTwo: null)

到这里:

return new CustomWidget(date: "date", content: "content", trailingIconOne: Icon(Icons.add), trailingIconTwo: Icon(Icons.add))

【讨论】:

    猜你喜欢
    • 2021-05-12
    • 1970-01-01
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    • 2020-12-14
    • 1970-01-01
    • 2019-06-24
    • 1970-01-01
    相关资源
    最近更新 更多