@@ -12,6 +12,40 @@ import 'action.dart';
1212
1313part 'set_variable_action.g.dart' ;
1414
15+ /// Defines the operation to be perfomed on a list type variable.
16+ enum ListOperation {
17+ /// Replace entire list.
18+ replace,
19+
20+ /// Add [newValue] to the list.
21+ add,
22+
23+ /// Insert [newValue] at [index] in the list.
24+ insert,
25+
26+ /// Remove value at [index] from the list.
27+ remove,
28+
29+ /// Update value at [index] with [newValue] in the list.
30+ update;
31+
32+ /// Returns a string representation of this enum.
33+ String get prettify {
34+ switch (this ) {
35+ case ListOperation .replace:
36+ return 'Replace' ;
37+ case ListOperation .add:
38+ return 'Add' ;
39+ case ListOperation .insert:
40+ return 'Insert' ;
41+ case ListOperation .remove:
42+ return 'Remove' ;
43+ case ListOperation .update:
44+ return 'Update' ;
45+ }
46+ }
47+ }
48+
1549/// An action that sets value of a variable.
1650@JsonSerializable ()
1751class SetVariableAction extends ActionModel
@@ -26,11 +60,20 @@ class SetVariableAction extends ActionModel
2660 /// if the variable is a boolean.
2761 final bool toggled;
2862
63+ final ListOperation listOperation;
64+
65+ /// Index of the value to be updated/removed/inserted.
66+ /// Can be a discrete value or a variable refered by '${}' syntax.
67+ /// Used for list type variable.
68+ final String index;
69+
2970 /// Creates a new [SetValueAction] .
3071 SetVariableAction ({
3172 required this .variable,
3273 required this .newValue,
3374 this .toggled = false ,
75+ this .listOperation = ListOperation .replace,
76+ this .index = '0' ,
3477 }) : super (type: ActionType .setVariable);
3578
3679 @override
@@ -41,11 +84,15 @@ class SetVariableAction extends ActionModel
4184 VariableData ? variable,
4285 String ? newValue,
4386 bool ? toggled,
87+ ListOperation ? listOperation,
88+ String ? index,
4489 }) =>
4590 SetVariableAction (
4691 variable: variable ?? this .variable,
4792 newValue: newValue ?? this .newValue,
4893 toggled: toggled ?? this .toggled,
94+ listOperation: listOperation ?? this .listOperation,
95+ index: index ?? this .index,
4996 );
5097
5198 /// Creates a new [SetVariableAction] instance from a JSON data.
0 commit comments