Skip to content

Commit 3f3592f

Browse files
committed
Saad Style Sheets #18
1 parent afb5476 commit 3f3592f

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

lib/src/api/models/paint.dart

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,35 @@ class PaintModel with EquatableMixin, SerializableMixin {
484484
}
485485
}
486486

487+
/// [PaintModel]s differentiate themselves with an [id], so we
488+
/// need to manually compare the other fields.
489+
bool isEquivalentTo(PaintModel? other) {
490+
if (other == null) return false;
491+
if (type != other.type) return false;
492+
if (visible != other.visible) return false;
493+
if (opacity != other.opacity) return false;
494+
if (color != other.color) return false;
495+
if (blendMode != other.blendMode) return false;
496+
if (gradientTransform != other.gradientTransform) return false;
497+
if (gradientStops != other.gradientStops) return false;
498+
if (imageTransform != other.imageTransform) return false;
499+
if (hasImageBytes != other.hasImageBytes) return false;
500+
if (downloadUrl != other.downloadUrl) return false;
501+
if (imageName != other.imageName) return false;
502+
if (imageHash != other.imageHash) return false;
503+
if (fit != other.fit) return false;
504+
if (alignment != other.alignment) return false;
505+
if (scaleX != other.scaleX) return false;
506+
if (scaleY != other.scaleY) return false;
507+
if (imageRepeat != other.imageRepeat) return false;
508+
if (assetID != other.assetID) return false;
509+
if (sourceWidth != other.sourceWidth) return false;
510+
if (sourceHeight != other.sourceHeight) return false;
511+
if (cropData != other.cropData) return false;
512+
if (croppedImageURL != other.croppedImageURL) return false;
513+
return true;
514+
}
515+
487516
@override
488517
List<Object?> get props => [
489518
id,
@@ -498,17 +527,17 @@ class PaintModel with EquatableMixin, SerializableMixin {
498527
hasImageBytes,
499528
downloadUrl,
500529
imageName,
501-
scaleX,
502-
scaleY,
503530
imageHash,
504-
alignment,
505531
fit,
506-
cropData,
507-
croppedImageURL,
508-
sourceWidth,
509-
sourceHeight,
532+
alignment,
533+
scaleX,
534+
scaleY,
510535
imageRepeat,
511536
assetID,
537+
sourceWidth,
538+
sourceHeight,
539+
cropData,
540+
croppedImageURL,
512541
];
513542

514543
/// Factory constructor for creating [PaintModel] instance from a JSON data.

lib/src/api/models/start_end_prop.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ class StartEndProp extends TextProp {
7979
super.isJsonPath,
8080
});
8181

82+
/// Creates a [StartEndProp] with the given data from a [TextProp].
83+
StartEndProp.fromTextProp(
84+
{required this.start, required this.end, required TextProp prop})
85+
: super(
86+
fills: prop.fills,
87+
textDecoration: prop.textDecoration,
88+
letterSpacing: prop.letterSpacing,
89+
fontSize: prop.fontSize,
90+
fontName: prop.fontName,
91+
lineHeight: prop.lineHeight,
92+
link: prop.link,
93+
isJsonPath: prop.isJsonPath,
94+
);
95+
8296
@override
8397
StartEndProp copyWith({
8498
int? start,
@@ -210,7 +224,7 @@ class TextProp extends Equatable with SerializableMixin {
210224
bool isEquivalentTo(TextProp? other) {
211225
return other != null &&
212226
fills.length == other.fills.length &&
213-
fills.every((e) => other.fills.contains(e)) &&
227+
fills.every((a) => other.fills.any((b) => a.isEquivalentTo(b))) &&
214228
textDecoration == other.textDecoration &&
215229
fontSize == other.fontSize &&
216230
letterSpacing == other.letterSpacing &&

0 commit comments

Comments
 (0)