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 # 2.4.4
* Remove unnecessary `new` and `const`. * 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); var rc = ReCase(type.typeArguments[0].name);
deserializedRepresentation = "map['$alias'] is Iterable" deserializedRepresentation = "map['$alias'] is Iterable"
" ? List.unmodifiable(((map['$alias'] as Iterable)" " ? List.unmodifiable(((map['$alias'] as Iterable)"
".where((x) => x is Map))" ".whereType<Map>())"
".cast<Map>()"
".map(${rc.pascalCase}Serializer.fromMap))" ".map(${rc.pascalCase}Serializer.fromMap))"
" : $defaultValue"; " : $defaultValue";
} else if (isMapToModelType(type)) { } else if (isMapToModelType(type)) {

View file

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

View file

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