The upcoming Dart 2.X release requires strong typing. When working with JSON data we must now cast dynamic
types to an appropriate Dart type (not a problem).
A
I wrote Ignoring cast fail from JSArray to List
So I add the
.cast
as the documentation and related link suggest and still receive the warning:() List
docFixBroken = json["data"].cast ().map( (s) => s.toUpperCase() ).toList(); List alsoBroken = List.from( (json["data"] as List).cast () ).map( (s) => s.toUpperCase() ).toList();
Unfortunately, List.from
does not persist type information, due to the lack of generic types for factory constructors (https://github.com/dart-lang/sdk/issues/26391). Until then, you should/could use .toList()
instead:
(json['data'] as List).toList()
So, rewriting your examples:
List
docFixBroken = json["data"].cast ().map( (s) => s.toUpperCase() ).toList(); List alsoBroken = List.from( (json["data"] as List).cast () ).map( (s) => s.toUpperCase() ).toList();
Can be written as:
List notBroken = (json['data'] as List).cast((s) => s.toUpperCase()).toList();
Hope that helps!