Use whereType() instead of chaining where() and cast().

This commit is contained in:
Tobe O 2019-07-04 14:08:25 -04:00
parent 165dd82813
commit a4b56e7885
4 changed files with 9 additions and 10 deletions

View file

@ -1,3 +1,7 @@
# 2.5.0
* Support mutable models (again).
* Use `whereType()` instead of chaining `where()` and `cast()`.
# 2.4.4
* Remove unnecessary `new` and `const`.

View file

@ -282,8 +282,7 @@ class ${pascal}Decoder extends Converter<Map, ${pascal}> {
var rc = ReCase(type.typeArguments[0].name);
deserializedRepresentation = "map['$alias'] is Iterable"
" ? List.unmodifiable(((map['$alias'] as Iterable)"
".where((x) => x is Map))"
".cast<Map>()"
".whereType<Map>())"
".map(${rc.pascalCase}Serializer.fromMap))"
" : $defaultValue";
} else if (isMapToModelType(type)) {

View file

@ -479,10 +479,8 @@ class AuthorSerializer extends Codec<Author, Map> {
name: map['name'] as String,
age: map['age'] as int,
books: map['books'] is Iterable
? List.unmodifiable(
((map['books'] as Iterable).where((x) => x is Map))
.cast<Map>()
.map(BookSerializer.fromMap))
? List.unmodifiable(((map['books'] as Iterable).whereType<Map>())
.map(BookSerializer.fromMap))
: null,
newestBook: map['newest_book'] != null
? BookSerializer.fromMap(map['newest_book'] as Map)

View file

@ -160,10 +160,8 @@ class GamepadSerializer extends Codec<Gamepad, Map> {
static Gamepad fromMap(Map map) {
return Gamepad(
buttons: map['buttons'] is Iterable
? List.unmodifiable(
((map['buttons'] as Iterable).where((x) => x is Map))
.cast<Map>()
.map(GamepadButtonSerializer.fromMap))
? List.unmodifiable(((map['buttons'] as Iterable).whereType<Map>())
.map(GamepadButtonSerializer.fromMap))
: null,
dynamicMap: map['dynamic_map'] is Map
? (map['dynamic_map'] as Map).cast<String, dynamic>()