@@ -18,7 +18,13 @@ class ChildWithNullable {
1818 this .otherProperty,
1919 });
2020
21- ChildWithNullableTypeEnum ? type;
21+ ///
22+ /// Please note: This property should have been non-nullable! Since the specification file
23+ /// does not include a default value (using the "default:" property), however, the generated
24+ /// source code must fall back to having a nullable type.
25+ /// Consider adding a "default:" property in the specification file to hide this note.
26+ ///
27+ String ? type;
2228
2329 String ? nullableProperty;
2430
@@ -85,7 +91,7 @@ class ChildWithNullable {
8591 }());
8692
8793 return ChildWithNullable (
88- type: ChildWithNullableTypeEnum . fromJson (json[ r'type' ] ),
94+ type: mapValueOfType < String > (json, r'type' ),
8995 nullableProperty: mapValueOfType <String >(json, r'nullableProperty' ),
9096 otherProperty: mapValueOfType <String >(json, r'otherProperty' ),
9197 );
@@ -138,74 +144,3 @@ class ChildWithNullable {
138144 };
139145}
140146
141-
142- class ChildWithNullableTypeEnum {
143- /// Instantiate a new enum with the provided [value] .
144- const ChildWithNullableTypeEnum ._(this .value);
145-
146- /// The underlying value of this enum member.
147- final String value;
148-
149- @override
150- String toString () => value;
151-
152- String toJson () => value;
153-
154- static const childWithNullable = ChildWithNullableTypeEnum ._(r'ChildWithNullable' );
155-
156- /// List of all possible values in this [enum][ChildWithNullableTypeEnum] .
157- static const values = < ChildWithNullableTypeEnum > [
158- childWithNullable,
159- ];
160-
161- static ChildWithNullableTypeEnum ? fromJson (dynamic value) => ChildWithNullableTypeEnumTypeTransformer ().decode (value);
162-
163- static List <ChildWithNullableTypeEnum > listFromJson (dynamic json, {bool growable = false ,}) {
164- final result = < ChildWithNullableTypeEnum > [];
165- if (json is List && json.isNotEmpty) {
166- for (final row in json) {
167- final value = ChildWithNullableTypeEnum .fromJson (row);
168- if (value != null ) {
169- result.add (value);
170- }
171- }
172- }
173- return result.toList (growable: growable);
174- }
175- }
176-
177- /// Transformation class that can [encode] an instance of [ChildWithNullableTypeEnum] to String,
178- /// and [decode] dynamic data back to [ChildWithNullableTypeEnum] .
179- class ChildWithNullableTypeEnumTypeTransformer {
180- factory ChildWithNullableTypeEnumTypeTransformer () => _instance ?? = const ChildWithNullableTypeEnumTypeTransformer ._();
181-
182- const ChildWithNullableTypeEnumTypeTransformer ._();
183-
184- String encode (ChildWithNullableTypeEnum data) => data.value;
185-
186- /// Decodes a [dynamic value][data] to a ChildWithNullableTypeEnum.
187- ///
188- /// If [allowNull] is true and the [dynamic value][data] cannot be decoded successfully,
189- /// then null is returned. However, if [allowNull] is false and the [dynamic value][data]
190- /// cannot be decoded successfully, then an [UnimplementedError] is thrown.
191- ///
192- /// The [allowNull] is very handy when an API changes and a new enum value is added or removed,
193- /// and users are still using an old app with the old code.
194- ChildWithNullableTypeEnum ? decode (dynamic data, {bool allowNull = true }) {
195- if (data != null ) {
196- switch (data) {
197- case r'ChildWithNullable' : return ChildWithNullableTypeEnum .childWithNullable;
198- default :
199- if (! allowNull) {
200- throw ArgumentError ('Unknown enum value to decode: $data ' );
201- }
202- }
203- }
204- return null ;
205- }
206-
207- /// Singleton [ChildWithNullableTypeEnumTypeTransformer] instance.
208- static ChildWithNullableTypeEnumTypeTransformer ? _instance;
209- }
210-
211-
0 commit comments