Skip to content

Commit f0cfeb6

Browse files
committed
Conditions #33
- Refactor PaintModel to make id field required. - Fix PaintModel & Effect usages to ensure id stays the same where it can. - Fix vanishing condition issue with stroke and shadows when colors are changed. - Implement per block error for conditions builder. - Fix predefined variables color to match with condition builder accent color. - Improve condition dialog resizing when conditions are added/removed. - Fix create new variable option if node is not inside a canvas. - Add validation checks for else condition with `PaintValue` and `ColorValue`.
1 parent 54f3f59 commit f0cfeb6

File tree

8 files changed

+61
-47
lines changed

8 files changed

+61
-47
lines changed

lib/src/api/models/color_rgb.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:math' as math;
77
import 'package:equatable/equatable.dart';
88
import 'package:json_annotation/json_annotation.dart';
99

10+
import '../../../codelessly_api.dart';
1011
import '../mixins.dart';
1112
import 'models.dart';
1213

@@ -73,6 +74,9 @@ class ColorRGB extends Equatable with SerializableMixin {
7374
Map toJson() => _$ColorRGBToJson(this);
7475

7576
/// Creates a [PaintModel] with this color and given [opacity].
76-
PaintModel toPaint([double opacity = 1.0]) =>
77-
PaintModel.solid(color: this, opacity: opacity);
77+
PaintModel toPaint([String? id, double opacity = 1.0]) => PaintModel.solid(
78+
id: id ?? generateId(),
79+
color: this,
80+
opacity: opacity,
81+
);
7882
}

lib/src/api/models/effect.dart

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

8-
import '../generate_id.dart';
98
import '../mixins.dart';
109
import 'models.dart';
1110

@@ -71,63 +70,63 @@ class Effect with EquatableMixin, SerializableMixin {
7170

7271
/// Creates new [Effect] with given data.
7372
Effect({
74-
String? id,
73+
required this.id,
7574
required this.type,
7675
required this.radius,
7776
this.visible = true,
7877
this.color,
7978
this.blendMode,
8079
this.offset,
8180
this.spread,
82-
}) : id = id ?? generateId();
81+
});
8382

8483
/// Creates a new [Effect] with drop shadow.
8584
Effect.dropShadow({
86-
String? id,
85+
required this.id,
8786
this.type = EffectType.dropShadow,
8887
required this.radius,
8988
this.visible = true,
9089
required this.color,
9190
required this.offset,
9291
required this.spread,
9392
this.blendMode,
94-
}) : id = id ?? generateId();
93+
});
9594

9695
/// Creates a new [Effect] with inner shadow.
9796
Effect.innerShadow({
98-
String? id,
97+
required this.id,
9998
this.type = EffectType.innerShadow,
10099
required this.radius,
101100
this.visible = true,
102101
required this.color,
103102
required this.offset,
104103
required this.spread,
105104
this.blendMode,
106-
}) : id = id ?? generateId();
105+
});
107106

108107
/// Creates a new [Effect] with layer blur.
109108
Effect.layerBlur({
110-
String? id,
109+
required this.id,
111110
this.type = EffectType.layerBlur,
112111
required this.radius,
113112
this.visible = true,
114113
this.color,
115114
this.blendMode,
116115
this.offset,
117116
this.spread,
118-
}) : id = id ?? generateId();
117+
});
119118

120119
/// Creates a new [Effect] with background blur.
121120
Effect.backgroundBlur({
122-
String? id,
121+
required this.id,
123122
this.type = EffectType.backgroundBlur,
124123
required this.radius,
125124
this.visible = true,
126125
this.color,
127126
this.blendMode,
128127
this.offset,
129128
this.spread,
130-
}) : id = id ?? generateId();
129+
});
131130

132131
/// Duplicates this instance with given data overrides.
133132
Effect copyWith({
@@ -140,6 +139,7 @@ class Effect with EquatableMixin, SerializableMixin {
140139
BlendModeC? blendMode,
141140
}) =>
142141
Effect(
142+
id: id,
143143
type: type ?? this.type,
144144
radius: radius ?? this.radius,
145145
visible: visible ?? this.visible,
@@ -151,6 +151,7 @@ class Effect with EquatableMixin, SerializableMixin {
151151

152152
@override
153153
List<Object?> get props => [
154+
id,
154155
type,
155156
visible,
156157
blendMode,

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/input_decoration.dart

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

8-
import '../mixins.dart';
9-
import 'models.dart';
8+
import '../../../codelessly_api.dart';
109

1110
part 'input_decoration.g.dart';
1211

@@ -231,10 +230,19 @@ class InputDecorationModel with EquatableMixin, SerializableMixin {
231230
helperStyle = helperStyle ??
232231
TextProp.general(fontSize: 14, fills: [PaintModel.blackPaint]),
233232
hintStyle = hintStyle ??
234-
TextProp.general(
235-
fontSize: 14, fills: [PaintModel.solid(color: ColorRGB.grey)]),
233+
TextProp.general(fontSize: 14, fills: [
234+
PaintModel.solid(
235+
id: generateId(),
236+
color: ColorRGB.grey,
237+
)
238+
]),
236239
errorStyle = errorStyle ??
237-
TextProp.general(fills: [PaintModel.solid(color: ColorRGB.red)]),
240+
TextProp.general(fills: [
241+
PaintModel.solid(
242+
id: generateId(),
243+
color: ColorRGB.red,
244+
)
245+
]),
238246
prefixStyle = prefixStyle ?? TextProp.general(),
239247
suffixStyle = suffixStyle ??
240248
TextProp.general(fontSize: 14, fills: [PaintModel.blackPaint]),

lib/src/api/models/paint.dart

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,27 +172,31 @@ class PaintModel with EquatableMixin, SerializableMixin {
172172

173173
/// Helper constructor for when a black paint is needed, like tests.
174174
static PaintModel get blackPaint => PaintModel.solid(
175+
id: generateId(),
175176
visible: true,
176177
opacity: 1.0,
177178
color: ColorRGB.black,
178179
);
179180

180181
/// Helper constructor for when a grey paint is needed, like tests.
181182
static PaintModel get greyPaint => PaintModel.solid(
183+
id: generateId(),
182184
visible: true,
183185
opacity: 1.0,
184186
color: ColorRGB.grey,
185187
);
186188

187189
/// Helper constructor for when a white paint is needed, like tests.
188190
static PaintModel get whitePaint => PaintModel.solid(
191+
id: generateId(),
189192
visible: true,
190193
opacity: 1.0,
191194
color: ColorRGB.white,
192195
);
193196

194197
/// Helper constructor for when a gradient paint is needed, like tests.
195198
static PaintModel get linearPaint => PaintModel(
199+
id: generateId(),
196200
type: PaintType.gradientLinear,
197201
visible: true,
198202
opacity: 1.0,
@@ -204,13 +208,12 @@ class PaintModel with EquatableMixin, SerializableMixin {
204208

205209
/// Create a Solid Paint with only the required properties.
206210
PaintModel.solid({
207-
String? id,
211+
required this.id,
208212
this.visible = true,
209213
this.opacity = 1,
210214
required this.color,
211215
this.blendMode = BlendModeC.srcOver,
212-
}) : id = id ?? generateId(),
213-
type = PaintType.solid,
216+
}) : type = PaintType.solid,
214217
hasImageBytes = false,
215218
cropData = null,
216219
croppedImageURL = null,
@@ -231,7 +234,7 @@ class PaintModel with EquatableMixin, SerializableMixin {
231234

232235
/// Create an Image Paint with only the required properties.
233236
PaintModel.image({
234-
String? id,
237+
required this.id,
235238
required this.downloadUrl,
236239
required this.fit,
237240
this.visible = true,
@@ -252,22 +255,20 @@ class PaintModel with EquatableMixin, SerializableMixin {
252255
this.assetID,
253256
}) : assert(sourceWidth != null && sourceHeight != null,
254257
'Images must always provide their original size.'),
255-
id = id ?? generateId(),
256258
type = PaintType.image,
257259
gradientTransform = null,
258260
gradientStops = null,
259261
color = null;
260262

261263
/// Creates [PaintModel] with linear gradient.
262264
PaintModel.linearGradient({
263-
String? id,
265+
required this.id,
264266
this.visible = true,
265267
this.opacity = 1,
266268
this.gradientTransform,
267269
this.gradientStops,
268270
this.blendMode = BlendModeC.srcOver,
269-
}) : id = id ?? generateId(),
270-
type = PaintType.gradientLinear,
271+
}) : type = PaintType.gradientLinear,
271272
color = null,
272273
imageTransform = null,
273274
hasImageBytes = false,
@@ -287,14 +288,13 @@ class PaintModel with EquatableMixin, SerializableMixin {
287288

288289
/// Creates [PaintModel] with radial gradient.
289290
PaintModel.radialGradient({
290-
String? id,
291+
required this.id,
291292
this.visible = true,
292293
this.opacity = 1,
293294
this.gradientTransform,
294295
this.gradientStops,
295296
this.blendMode = BlendModeC.srcOver,
296-
}) : id = id ?? generateId(),
297-
type = PaintType.gradientRadial,
297+
}) : type = PaintType.gradientRadial,
298298
color = null,
299299
imageTransform = null,
300300
hasImageBytes = false,
@@ -314,14 +314,13 @@ class PaintModel with EquatableMixin, SerializableMixin {
314314

315315
/// Creates [PaintModel] with angular gradient.
316316
PaintModel.angularGradient({
317-
String? id,
317+
required this.id,
318318
this.visible = true,
319319
this.opacity = 1,
320320
this.gradientTransform,
321321
this.gradientStops,
322322
this.blendMode = BlendModeC.srcOver,
323-
}) : id = id ?? generateId(),
324-
type = PaintType.gradientAngular,
323+
}) : type = PaintType.gradientAngular,
325324
color = null,
326325
imageTransform = null,
327326
hasImageBytes = false,
@@ -341,7 +340,7 @@ class PaintModel with EquatableMixin, SerializableMixin {
341340

342341
/// Creates [PaintModel] with given data.
343342
PaintModel({
344-
String? id,
343+
required this.id,
345344
required this.type,
346345
this.visible = true,
347346
this.opacity = 1,
@@ -364,7 +363,7 @@ class PaintModel with EquatableMixin, SerializableMixin {
364363
this.sourceHeight,
365364
this.assetID,
366365
this.imageRepeat = ImageRepeatEnum.noRepeat,
367-
}) : id = id ?? generateId();
366+
});
368367

369368
/// Duplicates this instance with given data overrides.
370369
PaintModel copyWith({
@@ -393,11 +392,10 @@ class PaintModel with EquatableMixin, SerializableMixin {
393392
double? sourceWidth,
394393
double? sourceHeight,
395394
ImageRepeatEnum? imageRepeat,
396-
String? id,
397395
bool forceSourceSize = false,
398396
}) =>
399397
PaintModel(
400-
id: id ?? this.id,
398+
id: id,
401399
type: type ?? this.type,
402400
visible: visible ?? this.visible,
403401
opacity: opacity ?? this.opacity,
@@ -434,6 +432,7 @@ class PaintModel with EquatableMixin, SerializableMixin {
434432
switch (type) {
435433
case PaintType.solid:
436434
return PaintModel.solid(
435+
id: id,
437436
color: color,
438437
blendMode: blendMode,
439438
opacity: opacity,
@@ -444,6 +443,7 @@ class PaintModel with EquatableMixin, SerializableMixin {
444443
case PaintType.gradientAngular:
445444
case PaintType.gradientDiamond:
446445
return PaintModel(
446+
id: id,
447447
type: type,
448448
blendMode: blendMode,
449449
opacity: opacity,
@@ -453,6 +453,7 @@ class PaintModel with EquatableMixin, SerializableMixin {
453453
);
454454
case PaintType.image:
455455
return PaintModel.image(
456+
id: id,
456457
downloadUrl: downloadUrl,
457458
fit: fit,
458459
sourceWidth: sourceWidth,

lib/src/api/models/paint.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/list_view_node.g.dart

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

0 commit comments

Comments
 (0)