【问题标题】:itemBuilder error: A non-null value must be returned since the return type 'Widget' doesn't allow nullitemBuilder 错误:必须返回非空值,因为返回类型“小部件”不允许为空
【发布时间】:2021-08-19 20:22:21
【问题描述】:

我正在尝试将 Firestore 数据库添加到我的 Flutter 项目中,但我不知道如何使用 ListView.builder 来显示数据库中数组上的每个元素,因为它给了我这个错误:@987654322 @ 第 56 行。 你可以帮帮我吗?这是代码:https://hastebin.com/ipayedezoc.js

提前致谢!

【问题讨论】:

  • firebase 会为您返回什么?
  • 什么意思?
  • 它是否返回任何数据?您在构建器方法中返回空值,而不是小部件。
  • 我的 firebase 应该返回一些字符串
  • 然后呢?您是否尝试打印字符串以检查它是否返回它应该返回的内容?

标签: flutter dart listview gradle


【解决方案1】:

有帮助吗?

 itemBuilder: (ctxt, i) {

                        ///for single item returns
                        // for(int i = 0; i < name['name'].length; i++){
                        //   ///may be you just to print out
                        // }
                        //  return ListTile(title: Text(name['name'][i])); 

                     ///for item list 
                     List<Widget> widgtes = [];
                        for(int i = 0; i < name['name'].length; i++){
                          ///may be you just to print out
                          widgtes.add(ListTile(title: Text(name['name'][i])));
                        }
                         return Column(
                           children: widgtes,
                         ); 

【讨论】:

    猜你喜欢
    • 2021-09-02
    • 1970-01-01
    • 2021-05-02
    • 1970-01-01
    • 2017-04-22
    • 1970-01-01
    • 2022-07-26
    • 1970-01-01
    • 2022-11-19
    相关资源
    最近更新 更多