Home > Mobile >  The argument type 'List<dynamic>' can't be assigned to the parameter type '
The argument type 'List<dynamic>' can't be assigned to the parameter type '

Time:11-12

I have upgraded my Flutter project version to the current latest flutter version (2.5.3) after upgraded occurs this error.

Code as follows,

final List<Object> _prop = [];

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

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

Error as follows,

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

CodePudding user response:

Error message tells us, List<dynamic> can't be assigned to List<Object>. In this case you provide parameter, default List is dynamic.

final List<Object> _prop = [];

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

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

  • Related