【问题标题】:The argument type 'List<dynamic>' can't be assigned to the parameter type 'Iterable<Object>'参数类型“List<dynamic>”不能分配给参数类型“Iterable<Object>”
【发布时间】:2021-12-24 15:33:09
【问题描述】:

我已经将我的Flutter项目版本升级到当前最新的flutter版本(2.5.3)升级后出现这个错误。

代码如下,

final List<Object> _prop = [];

@override
  List<Object> get prop => _prop;

  EnvironmentState([List prop = const []]) {
    this._prop.addAll(prop);         //        <------ Here is the error occurs
  }

错误如下,

The argument type 'List<dynamic>' can't be assigned to the parameter type 'Iterable<Object>

【问题讨论】:

    标签: flutter dart null-safety


    【解决方案1】:

    错误信息告诉我们,List&lt;dynamic&gt; 不能分配给List&lt;Object&gt;。在这种情况下,您提供参数,默认列表是动态的。

    final List<Object> _prop = [];
    
      @override
      List<Object> get prop => _prop;
    
      EnvironmentState([List<Object> prop = const []]) {
        this._prop.addAll(prop);  
      }
    
    

    【讨论】:

    • 很高兴为您提供帮助,您可以找到更多关于List的信息
    猜你喜欢
    • 2021-11-13
    • 2019-10-05
    • 2020-05-28
    • 2021-11-23
    • 2021-10-24
    • 2021-09-15
    • 2021-10-18
    • 2021-06-26
    • 2021-07-25
    相关资源
    最近更新 更多