【问题标题】:The argument type 'Object?' can't be assigned to the parameter type List参数类型“对象?”不能分配给参数类型 List
【发布时间】:2021-11-06 18:49:37
【问题描述】:

我一直在尝试将我的应用程序转换为新的 Flutter 新版本,但出现此错误 The argument type Object? can't be assigned to the parameter type List that can't be fix.... 可以有人帮我解决这个问题

list() {
    return Expanded(
      child: FutureBuilder(
        future: employees,
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            return dataTable(List<Url>.from(snapshot.data));
          }

          if (null == snapshot.data || snapshot.data == 0) {
            return Text("Tiada Data");
          }

          return CircularProgressIndicator();
        },
      ),
    );
  }

【问题讨论】:

    标签: flutter datatable flutter-futurebuilder


    【解决方案1】:

    这是因为您需要转换FutureBuilder 的类型。根据您的代码,我推断employees 的类型为Future&lt;List&gt; 或至少Future&lt;Iterable&gt;,那么您应该像这样定义构建器的类型:

    FutureBuilder<Iterable>(
      future: employees,
      builder: (context, snapshot) {
        if (snapshot.hasData) {
          return dataTable(List<Url>.from(snapshot.data!));
        }
    
        // ...
      },
    ),
    

    【讨论】:

    • 参数类型 'List?'无法分配给参数类型“Iterable”我收到此错误
    • 你的可变员工类型是什么?
    • 您可能只需要强制转换为不可为空的 snapshot.data,如下所示:List&lt;Url&gt;.from(snapshot.data!)
    • 未来>员工;
    猜你喜欢
    • 2021-08-29
    • 2020-05-28
    • 2021-07-04
    • 2021-12-10
    • 2021-10-24
    • 2022-11-05
    • 2021-08-05
    • 2021-07-07
    • 1970-01-01
    相关资源
    最近更新 更多