Skip to content

Commit 529913a

Browse files
committed
Migrate examples to use augmentations.
1 parent 83377d0 commit 529913a

10 files changed

+183
-226
lines changed

example/lib/example.dart

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ class Person {
2929
this.lastOrder,
3030
List<Order>? orders,
3131
}) : orders = orders ?? <Order>[];
32-
33-
factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);
34-
35-
Map<String, dynamic> toJson() => _$PersonToJson(this);
3632
}
3733

3834
@JsonSerializable(includeIfNull: false)
@@ -53,10 +49,6 @@ class Order {
5349

5450
Order(this.date);
5551

56-
factory Order.fromJson(Map<String, dynamic> json) => _$OrderFromJson(json);
57-
58-
Map<String, dynamic> toJson() => _$OrderToJson(this);
59-
6052
static Duration? _durationFromMilliseconds(int? milliseconds) =>
6153
milliseconds == null ? null : Duration(milliseconds: milliseconds);
6254

@@ -77,11 +69,9 @@ class Item {
7769
bool? isRushed;
7870

7971
Item();
80-
81-
factory Item.fromJson(Map<String, dynamic> json) => _$ItemFromJson(json);
82-
83-
Map<String, dynamic> toJson() => _$ItemToJson(this);
8472
}
8573

74+
// TODO(augment): Could model this a couple of ways, but decided to do a
75+
// variable declaration with no initializer.
8676
@JsonLiteral('data.json')
87-
Map get glossaryData => _$glossaryDataJsonLiteral;
77+
final Map glossaryData;

example/lib/example.g.dart

Lines changed: 57 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/lib/generic_response_class_example.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ class BaseResponse<T> {
2424
this.data,
2525
});
2626

27-
factory BaseResponse.fromJson(Map<String, dynamic> json) =>
28-
_$BaseResponseFromJson(json);
29-
3027
/// Decodes [json] by "inspecting" its contents.
3128
static T _dataFromJson<T>(Object json) {
3229
if (json is Map<String, dynamic>) {
@@ -70,9 +67,6 @@ class Article {
7067
this.author,
7168
this.comments,
7269
});
73-
74-
factory Article.fromJson(Map<String, dynamic> json) =>
75-
_$ArticleFromJson(json);
7670
}
7771

7872
@JsonSerializable(createToJson: false)
@@ -84,8 +78,6 @@ class User {
8478
this.id,
8579
this.email,
8680
});
87-
88-
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
8981
}
9082

9183
@JsonSerializable(createToJson: false)
@@ -97,7 +89,4 @@ class Comment {
9789
this.id,
9890
this.content,
9991
});
100-
101-
factory Comment.fromJson(Map<String, dynamic> json) =>
102-
_$CommentFromJson(json);
10392
}

example/lib/generic_response_class_example.g.dart

Lines changed: 31 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/lib/json_converter_example.dart

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ class DateTimeExample {
1616
final DateTime when;
1717

1818
DateTimeExample(this.when);
19-
20-
factory DateTimeExample.fromJson(Map<String, dynamic> json) =>
21-
_$DateTimeExampleFromJson(json);
22-
23-
Map<String, dynamic> toJson() => _$DateTimeExampleToJson(this);
2419
}
2520

2621
class _DateTimeEpochConverter implements JsonConverter<DateTime, int> {
@@ -54,11 +49,6 @@ class GenericCollection<T> {
5449
this.totalPages,
5550
this.results,
5651
});
57-
58-
factory GenericCollection.fromJson(Map<String, dynamic> json) =>
59-
_$GenericCollectionFromJson<T>(json);
60-
61-
Map<String, dynamic> toJson() => _$GenericCollectionToJson(this);
6252
}
6353

6454
class _Converter<T> implements JsonConverter<T, Object?> {
@@ -91,11 +81,6 @@ class CustomResult {
9181

9282
CustomResult(this.name, this.size);
9383

94-
factory CustomResult.fromJson(Map<String, dynamic> json) =>
95-
_$CustomResultFromJson(json);
96-
97-
Map<String, dynamic> toJson() => _$CustomResultToJson(this);
98-
9984
@override
10085
bool operator ==(Object other) =>
10186
other is CustomResult && other.name == name && other.size == size;

example/lib/json_converter_example.g.dart

Lines changed: 41 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/lib/nested_values_example.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@ part 'nested_values_example.g.dart';
88
class NestedValueExample {
99
NestedValueExample(this.nestedValues);
1010

11-
factory NestedValueExample.fromJson(Map<String, dynamic> json) =>
12-
_$NestedValueExampleFromJson(json);
13-
1411
@_NestedListConverter()
1512
@JsonKey(name: 'root_items')
1613
final List<String> nestedValues;
17-
18-
Map<String, dynamic> toJson() => _$NestedValueExampleToJson(this);
1914
}
2015

2116
class _NestedListConverter

0 commit comments

Comments
 (0)