Skip to content

Commit 2dfc230

Browse files
committed
Conditions #47
- improve backward compatibility for PaintModel and Effect. - rerun builder runner.
1 parent ef9e80d commit 2dfc230

20 files changed

+69
-69
lines changed

lib/src/api/mixins.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import 'package:json_annotation/json_annotation.dart';
66
import 'package:meta/meta.dart';
77

8-
import 'extensions.dart';
98
import 'models/models.dart';
109
import 'nodes/nodes.dart';
1110

lib/src/api/models/effect.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,15 @@ enum ShadowProperty {
4141
radius;
4242
}
4343

44+
/// Generates a random id if the given [json] does not contain a value for the
45+
/// given [key]. Required for backwards compatibility.
46+
Object? _readId(Map json, String key) => json[key] ?? generateId();
47+
4448
/// A visual effect such as a shadow or blur.
4549
@JsonSerializable()
4650
class Effect with EquatableMixin, SerializableMixin {
51+
52+
@JsonKey(readValue: _readId)
4753
/// Unique identifier of the effect.
4854
final String id;
4955

lib/src/api/models/effect.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/models/paint.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ enum ImageRepeatEnum {
3333
final String label;
3434
}
3535

36+
/// Generates a random id if the given [json] does not contain a value for the
37+
/// given [key]. Required for backwards compatibility.
38+
Object? _readId(Map json, String key) => json[key] ?? generateId();
39+
3640
/// A solid color, gradient, or image texture that can be applied as fill or
3741
/// stroke.
3842
@JsonSerializable()
3943
class PaintModel with EquatableMixin, SerializableMixin {
4044
/// identifier of this paint.
41-
@JsonKey(required: true)
45+
@JsonKey(readValue: _readId)
4246
final String id;
4347

4448
/// Type of paint.
@@ -507,11 +511,7 @@ class PaintModel with EquatableMixin, SerializableMixin {
507511
];
508512

509513
/// Factory constructor for creating [PaintModel] instance from a JSON data.
510-
factory PaintModel.fromJson(Map json) => _$PaintModelFromJson({
511-
// TODO: backward compatibility, remove in 1.0.0
512-
'id': generateId(),
513-
...json,
514-
});
514+
factory PaintModel.fromJson(Map json) => _$PaintModelFromJson(json);
515515

516516
@override
517517
Map toJson() => _$PaintModelToJson(this);

lib/src/api/models/paint.g.dart

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

lib/src/api/nodes/accordion_node.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/nodes/auto_placeholder_node.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/nodes/button_node.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/nodes/canvas_node.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/api/nodes/checkbox_node.g.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)