Skip to content

Commit 4af6cd8

Browse files
committed
Fix dropdown onChanged callback value.
1 parent b22e47b commit 4af6cd8

4 files changed

Lines changed: 69 additions & 3 deletions

File tree

lib/src/api/models/action/set_value_action.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ enum ValueType {
9797

9898
/// Represents a paint value which can be color, gradient, etc.
9999
paint,
100+
101+
/// Represents a object value.
102+
object,
100103
}
101104

102105
/// Represents a value to set in a node.
@@ -159,6 +162,8 @@ abstract class ValueModel<T extends Object?> with SerializableMixin {
159162
return ColorValue.fromJson(json);
160163
case ValueType.paint:
161164
return PaintValue.fromJson(json);
165+
case ValueType.object:
166+
return ObjectValue.fromJson(json);
162167
}
163168
}
164169
}
@@ -308,6 +313,37 @@ class StringValue extends ValueModel<String> with SerializableMixin {
308313
Map toJson() => _$StringValueToJson(this);
309314
}
310315

316+
/// Value of string type.
317+
@JsonSerializable()
318+
class ObjectValue extends ValueModel<Object?> with SerializableMixin {
319+
/// Creates a new [StringValue].
320+
ObjectValue({
321+
required super.name,
322+
SetValueMode mode = SetValueMode.syncValue,
323+
super.value = '',
324+
}) : super(type: ValueType.object, mode: SetValueMode.syncValue) {
325+
// assert(
326+
// mode != SetValueMode.syncValue, '${mode.prettify} mode not supported.');
327+
}
328+
329+
@override
330+
ObjectValue copyWith({
331+
SetValueMode? mode,
332+
Object? value,
333+
}) =>
334+
ObjectValue(
335+
name: name,
336+
mode: mode ?? this.mode,
337+
value: value ?? this.value,
338+
);
339+
340+
/// Creates a new [StringValue] instance from a JSON data.
341+
factory ObjectValue.fromJson(Map json) => _$ObjectValueFromJson(json);
342+
343+
@override
344+
Map toJson() => _$ObjectValueToJson(this);
345+
}
346+
311347
/// Value of boolean type.
312348
@JsonSerializable()
313349
class ColorValue extends ValueModel<ColorRGBA?> with SerializableMixin {

lib/src/api/models/action/set_value_action.g.dart

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

lib/src/api/nodes/dropdown_node.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class DropdownNode extends SceneNode with CustomPropertiesMixin {
2424
covariant DropdownProperties properties;
2525

2626
/// Index of the selected option in the dropdown.
27-
int? value;
27+
Object? value;
2828

2929
/// Creates a [DropdownNode] with the given data.
3030
DropdownNode({
@@ -57,7 +57,7 @@ class DropdownNode extends SceneNode with CustomPropertiesMixin {
5757
@override
5858
late final List<ValueModel> propertyVariables = [
5959
...super.propertyVariables,
60-
IntValue(name: 'value', value: value ?? -1),
60+
ObjectValue(name: 'value', value: value),
6161
];
6262

6363
@override

lib/src/api/nodes/dropdown_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)