Skip to content

Commit 3d0d52d

Browse files
committed
Conditions #36
- Add backward compatability for paint and effect model id field.
1 parent 7d0776d commit 3d0d52d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/src/api/models/effect.dart

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

8+
import '../generate_id.dart';
89
import '../mixins.dart';
910
import 'models.dart';
1011

@@ -162,7 +163,11 @@ class Effect with EquatableMixin, SerializableMixin {
162163
];
163164

164165
/// Factory constructor for creating new [Effect] from JSON data.
165-
factory Effect.fromJson(Map json) => _$EffectFromJson(json);
166+
factory Effect.fromJson(Map json) => _$EffectFromJson({
167+
// TODO: backward compatibility, remove in 1.0.0
168+
'id': generateId(),
169+
...json,
170+
});
166171

167172
@override
168173
Map toJson() => _$EffectToJson(this);

lib/src/api/models/paint.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ enum ImageRepeatEnum {
3838
@JsonSerializable()
3939
class PaintModel with EquatableMixin, SerializableMixin {
4040
/// identifier of this paint.
41+
@JsonKey(required: true)
4142
final String id;
4243

4344
/// Type of paint.
@@ -480,6 +481,7 @@ class PaintModel with EquatableMixin, SerializableMixin {
480481

481482
@override
482483
List<Object?> get props => [
484+
id,
483485
type,
484486
visible,
485487
opacity,
@@ -505,7 +507,11 @@ class PaintModel with EquatableMixin, SerializableMixin {
505507
];
506508

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

510516
@override
511517
Map toJson() => _$PaintModelToJson(this);

0 commit comments

Comments
 (0)