I have a from json method in my class but i'm getting an error in this part of the method:
timeToSpendEachDay:
(map['timeToSpendEachDay'] as Map<String, dynamic>).map<Days, Time>(
(key, value) =>
MapEntry<Days, Time>(_stringToDay(key), Time(value as int)),
),
There is a red line under the first value saying Missing parameter type for 'value'.
this can be fixed by changing dynamic to int but when i do that another error comes when i run the script saying:
type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Map<String, int>' in type cast
So how can i fix this?
CodePudding user response:
The language does not require a type at that point, so what you see must be a result of extra enabled lints or analyzer options. Since the type of value is dynamic, it's probably "strict-inference" being set to true in your analysis_options.yaml file, or the --no-implicit-dynamic command line flag.
I'd change the parameter to , dynamic value to make the dynamic type explicit (and therefore not inferred). Alternatively, make it , Object? value, since all you do is as int on it anyway, you don't use the dynamic type for anything.
