1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 22:09:06 +00:00

jsonexample maintenance (#150)

* jsonexample maintenance

* formatting
This commit is contained in:
John Ryan
2019-10-08 08:52:47 -07:00
committed by GitHub
parent 74c1777b2a
commit dfba162762
9 changed files with 65 additions and 62 deletions

View File

@@ -30,6 +30,16 @@ instantiating models and populating their fields.
Each tab page in the app deserializes one type of data with one library. Each tab page in the app deserializes one type of data with one library.
These Widgets show what app code using the above libraries might look like. These Widgets show what app code using the above libraries might look like.
## Generating
The lib/build_value and lib/json_serializable use build_runner to generate
files. If you make a change to these files, you need to re-run the generator
using `build_runner`:
```
flutter pub run build_runner build
```
## Questions/issues ## Questions/issues
If you have a general question about JSON serialization in Flutter, the If you have a general question about JSON serialization in Flutter, the

View File

@@ -1,8 +1,9 @@
include: package:pedantic/analysis_options.1.7.0.yaml include: package:pedantic/analysis_options.1.8.0.yaml
analyzer: analyzer:
exclude: exclude:
- lib/json_serializable/*.g.dart - lib/json_serializable/*.g.dart
- lib/built_value/*.g.dart
strong-mode: strong-mode:
implicit-casts: false implicit-casts: false
implicit-dynamic: false implicit-dynamic: false

View File

@@ -4,13 +4,6 @@ targets:
built_value_generator|built_value: built_value_generator|built_value:
generate_for: generate_for:
- lib/built_value/*.dart - lib/built_value/*.dart
options:
header: |
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// GENERATED CODE - DO NOT MODIFY BY HAND
json_serializable|json_serializable: json_serializable|json_serializable:
generate_for: generate_for:
- lib/json_serializable/*.dart - lib/json_serializable/*.dart

View File

@@ -17,7 +17,7 @@ class _$BuiltComplexObjectSerializer
final String wireName = 'BuiltComplexObject'; final String wireName = 'BuiltComplexObject';
@override @override
Iterable serialize(Serializers serializers, BuiltComplexObject object, Iterable<Object> serialize(Serializers serializers, BuiltComplexObject object,
{FullType specifiedType = FullType.unspecified}) { {FullType specifiedType = FullType.unspecified}) {
final result = <Object>[]; final result = <Object>[];
if (object.aString != null) { if (object.aString != null) {
@@ -72,12 +72,12 @@ class _$BuiltComplexObjectSerializer
specifiedType: const FullType( specifiedType: const FullType(
BuiltList, const [const FullType(BuiltSimpleObject)]))); BuiltList, const [const FullType(BuiltSimpleObject)])));
} }
return result; return result;
} }
@override @override
BuiltComplexObject deserialize(Serializers serializers, Iterable serialized, BuiltComplexObject deserialize(
Serializers serializers, Iterable<Object> serialized,
{FullType specifiedType = FullType.unspecified}) { {FullType specifiedType = FullType.unspecified}) {
final result = new BuiltComplexObjectBuilder(); final result = new BuiltComplexObjectBuilder();
@@ -108,25 +108,25 @@ class _$BuiltComplexObjectSerializer
result.aListOfStrings.replace(serializers.deserialize(value, result.aListOfStrings.replace(serializers.deserialize(value,
specifiedType: specifiedType:
const FullType(BuiltList, const [const FullType(String)])) const FullType(BuiltList, const [const FullType(String)]))
as BuiltList); as BuiltList<dynamic>);
break; break;
case 'aListOfInts': case 'aListOfInts':
result.aListOfInts.replace(serializers.deserialize(value, result.aListOfInts.replace(serializers.deserialize(value,
specifiedType: specifiedType:
const FullType(BuiltList, const [const FullType(int)])) const FullType(BuiltList, const [const FullType(int)]))
as BuiltList); as BuiltList<dynamic>);
break; break;
case 'aListOfDoubles': case 'aListOfDoubles':
result.aListOfDoubles.replace(serializers.deserialize(value, result.aListOfDoubles.replace(serializers.deserialize(value,
specifiedType: specifiedType:
const FullType(BuiltList, const [const FullType(double)])) const FullType(BuiltList, const [const FullType(double)]))
as BuiltList); as BuiltList<dynamic>);
break; break;
case 'aListOfObjects': case 'aListOfObjects':
result.aListOfObjects.replace(serializers.deserialize(value, result.aListOfObjects.replace(serializers.deserialize(value,
specifiedType: const FullType( specifiedType: const FullType(
BuiltList, const [const FullType(BuiltSimpleObject)])) BuiltList, const [const FullType(BuiltSimpleObject)]))
as BuiltList); as BuiltList<dynamic>);
break; break;
} }
} }

View File

@@ -17,7 +17,7 @@ class _$BuiltSimpleObjectSerializer
final String wireName = 'BuiltSimpleObject'; final String wireName = 'BuiltSimpleObject';
@override @override
Iterable serialize(Serializers serializers, BuiltSimpleObject object, Iterable<Object> serialize(Serializers serializers, BuiltSimpleObject object,
{FullType specifiedType = FullType.unspecified}) { {FullType specifiedType = FullType.unspecified}) {
final result = <Object>[]; final result = <Object>[];
if (object.aString != null) { if (object.aString != null) {
@@ -59,12 +59,12 @@ class _$BuiltSimpleObjectSerializer
specifiedType: specifiedType:
const FullType(BuiltList, const [const FullType(double)]))); const FullType(BuiltList, const [const FullType(double)])));
} }
return result; return result;
} }
@override @override
BuiltSimpleObject deserialize(Serializers serializers, Iterable serialized, BuiltSimpleObject deserialize(
Serializers serializers, Iterable<Object> serialized,
{FullType specifiedType = FullType.unspecified}) { {FullType specifiedType = FullType.unspecified}) {
final result = new BuiltSimpleObjectBuilder(); final result = new BuiltSimpleObjectBuilder();
@@ -90,19 +90,19 @@ class _$BuiltSimpleObjectSerializer
result.aListOfStrings.replace(serializers.deserialize(value, result.aListOfStrings.replace(serializers.deserialize(value,
specifiedType: specifiedType:
const FullType(BuiltList, const [const FullType(String)])) const FullType(BuiltList, const [const FullType(String)]))
as BuiltList); as BuiltList<dynamic>);
break; break;
case 'aListOfInts': case 'aListOfInts':
result.aListOfInts.replace(serializers.deserialize(value, result.aListOfInts.replace(serializers.deserialize(value,
specifiedType: specifiedType:
const FullType(BuiltList, const [const FullType(int)])) const FullType(BuiltList, const [const FullType(int)]))
as BuiltList); as BuiltList<dynamic>);
break; break;
case 'aListOfDoubles': case 'aListOfDoubles':
result.aListOfDoubles.replace(serializers.deserialize(value, result.aListOfDoubles.replace(serializers.deserialize(value,
specifiedType: specifiedType:
const FullType(BuiltList, const [const FullType(double)])) const FullType(BuiltList, const [const FullType(double)]))
as BuiltList); as BuiltList<dynamic>);
break; break;
} }
} }

View File

@@ -18,8 +18,7 @@ SerializableComplexObject _$SerializableComplexObjectFromJson(
json['anObject'] as Map<String, dynamic>), json['anObject'] as Map<String, dynamic>),
aListOfStrings: aListOfStrings:
(json['aListOfStrings'] as List)?.map((e) => e as String)?.toList(), (json['aListOfStrings'] as List)?.map((e) => e as String)?.toList(),
aListOfInts: aListOfInts: (json['aListOfInts'] as List)?.map((e) => e as int)?.toList(),
(json['aListOfInts'] as List)?.map((e) => e as int)?.toList(),
aListOfDoubles: (json['aListOfDoubles'] as List) aListOfDoubles: (json['aListOfDoubles'] as List)
?.map((e) => (e as num)?.toDouble()) ?.map((e) => (e as num)?.toDouble())
?.toList(), ?.toList(),
@@ -27,7 +26,8 @@ SerializableComplexObject _$SerializableComplexObjectFromJson(
?.map((e) => e == null ?.map((e) => e == null
? null ? null
: SerializableSimpleObject.fromJson(e as Map<String, dynamic>)) : SerializableSimpleObject.fromJson(e as Map<String, dynamic>))
?.toList()); ?.toList(),
);
} }
Map<String, dynamic> _$SerializableComplexObjectToJson( Map<String, dynamic> _$SerializableComplexObjectToJson(
@@ -40,5 +40,5 @@ Map<String, dynamic> _$SerializableComplexObjectToJson(
'aListOfStrings': instance.aListOfStrings, 'aListOfStrings': instance.aListOfStrings,
'aListOfInts': instance.aListOfInts, 'aListOfInts': instance.aListOfInts,
'aListOfDoubles': instance.aListOfDoubles, 'aListOfDoubles': instance.aListOfDoubles,
'aListOfObjects': instance.aListOfObjects 'aListOfObjects': instance.aListOfObjects,
}; };

View File

@@ -14,11 +14,11 @@ SerializableSimpleObject _$SerializableSimpleObjectFromJson(
aDouble: (json['aDouble'] as num)?.toDouble(), aDouble: (json['aDouble'] as num)?.toDouble(),
aListOfStrings: aListOfStrings:
(json['aListOfStrings'] as List)?.map((e) => e as String)?.toList(), (json['aListOfStrings'] as List)?.map((e) => e as String)?.toList(),
aListOfInts: aListOfInts: (json['aListOfInts'] as List)?.map((e) => e as int)?.toList(),
(json['aListOfInts'] as List)?.map((e) => e as int)?.toList(),
aListOfDoubles: (json['aListOfDoubles'] as List) aListOfDoubles: (json['aListOfDoubles'] as List)
?.map((e) => (e as num)?.toDouble()) ?.map((e) => (e as num)?.toDouble())
?.toList()); ?.toList(),
);
} }
Map<String, dynamic> _$SerializableSimpleObjectToJson( Map<String, dynamic> _$SerializableSimpleObjectToJson(
@@ -29,5 +29,5 @@ Map<String, dynamic> _$SerializableSimpleObjectToJson(
'aDouble': instance.aDouble, 'aDouble': instance.aDouble,
'aListOfStrings': instance.aListOfStrings, 'aListOfStrings': instance.aListOfStrings,
'aListOfInts': instance.aListOfInts, 'aListOfInts': instance.aListOfInts,
'aListOfDoubles': instance.aListOfDoubles 'aListOfDoubles': instance.aListOfDoubles,
}; };

View File

@@ -42,7 +42,7 @@ packages:
name: build name: build
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.1.6" version: "1.2.0"
build_config: build_config:
dependency: transitive dependency: transitive
description: description:
@@ -56,28 +56,28 @@ packages:
name: build_daemon name: build_daemon
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.0" version: "2.1.0"
build_resolvers: build_resolvers:
dependency: transitive dependency: transitive
description: description:
name: build_resolvers name: build_resolvers
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.0.7" version: "1.1.1"
build_runner: build_runner:
dependency: "direct dev" dependency: "direct dev"
description: description:
name: build_runner name: build_runner
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.6.8" version: "1.7.1"
build_runner_core: build_runner_core:
dependency: transitive dependency: transitive
description: description:
name: build_runner_core name: build_runner_core
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.1.0" version: "4.1.0"
built_collection: built_collection:
dependency: "direct main" dependency: "direct main"
description: description:
@@ -140,7 +140,7 @@ packages:
name: crypto name: crypto
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.2" version: "2.1.3"
csslib: csslib:
dependency: transitive dependency: transitive
description: description:
@@ -199,7 +199,7 @@ packages:
name: html name: html
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.14.0+2" version: "0.14.0+3"
http: http:
dependency: transitive dependency: transitive
description: description:
@@ -456,6 +456,6 @@ packages:
name: yaml name: yaml
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.16" version: "2.2.0"
sdks: sdks:
dart: ">=2.5.0 <3.0.0" dart: ">=2.5.0 <3.0.0"

View File

@@ -13,7 +13,7 @@ dependencies:
sdk: flutter sdk: flutter
dev_dependencies: dev_dependencies:
build_runner: ^1.6.8 build_runner: ^1.7.1
built_value_generator: ^6.7.1 built_value_generator: ^6.7.1
json_serializable: ^3.2.2 json_serializable: ^3.2.2
pedantic: ^1.8.0+1 pedantic: ^1.8.0+1
@@ -23,4 +23,3 @@ dev_dependencies:
flutter: flutter:
uses-material-design: true uses-material-design: true