@@ -114,13 +114,24 @@ class VariableData
114114 /// metadata or any other information that is not part of the core variable.
115115 final Map <String , dynamic > extra;
116116
117+ /// A formula expression (what goes inside `${= ...}` ) that computes this
118+ /// variable's value from other variables, e.g. `fresh < freshLimit` . Empty
119+ /// for a variable that holds a value. A computed variable is read-only:
120+ /// actions that set it are ignored, and it changes whenever a variable its
121+ /// formula reads changes.
122+ final String formula;
123+
124+ /// Whether this variable's value comes from [formula] .
125+ bool get isComputed => formula.trim ().isNotEmpty;
126+
117127 /// Creates a new [VariableData] .
118128 VariableData ({
119129 required this .id,
120130 required this .name,
121131 Object ? value = '' ,
122132 this .type = VariableType .text,
123133 Map <String , dynamic >? extra,
134+ this .formula = '' ,
124135 }) : value = sanitizeValueForVariableType (value, type) ?? '' ,
125136 extra = extra ?? {};
126137
@@ -133,6 +144,7 @@ class VariableData
133144 bool ? isUsed,
134145 Set <String >? nodes,
135146 Map <String , dynamic >? extra,
147+ String ? formula,
136148 }) {
137149 final String ? sanitizedValue = value == null
138150 ? null
@@ -143,11 +155,12 @@ class VariableData
143155 value: sanitizedValue ?? this .value,
144156 type: type ?? this .type,
145157 extra: extra ?? this .extra,
158+ formula: formula ?? this .formula,
146159 );
147160 }
148161
149162 @override
150- List <Object ?> get props => [id, name, value, type];
163+ List <Object ?> get props => [id, name, value, type, formula ];
151164
152165 @override
153166 int compareTo (VariableData other) => name.compareTo (other.name);
@@ -168,6 +181,7 @@ class VariableData
168181 name: name,
169182 value: value,
170183 type: type,
184+ formula: formula,
171185 );
172186
173187 /// Returns the value converted to the appropriate type according to [type] .
@@ -243,6 +257,7 @@ class CanvasVariableData extends VariableData {
243257 super .type,
244258 super .value,
245259 super .extra,
260+ super .formula,
246261 });
247262
248263 @override
@@ -255,6 +270,7 @@ class CanvasVariableData extends VariableData {
255270 String ? canvasId,
256271 Set <String >? nodes,
257272 Map <String , dynamic >? extra,
273+ String ? formula,
258274 }) {
259275 final String ? sanitizedValue = value == null
260276 ? null
@@ -266,6 +282,7 @@ class CanvasVariableData extends VariableData {
266282 id: id ?? this .id,
267283 canvasId: canvasId ?? this .canvasId,
268284 extra: extra ?? this .extra,
285+ formula: formula ?? this .formula,
269286 );
270287 }
271288
@@ -301,6 +318,7 @@ class RuntimeVariableData extends VariableData {
301318 super .value = '' ,
302319 super .type = VariableType .text,
303320 super .extra,
321+ super .formula,
304322 }) : super (id: id ?? generateId ());
305323
306324 @override
@@ -312,6 +330,7 @@ class RuntimeVariableData extends VariableData {
312330 bool ? isUsed,
313331 Set <String >? nodes,
314332 Map <String , dynamic >? extra,
333+ String ? formula,
315334 }) {
316335 final String ? sanitizedValue = value == null
317336 ? null
@@ -322,6 +341,7 @@ class RuntimeVariableData extends VariableData {
322341 value: sanitizedValue ?? this .value,
323342 type: type ?? this .type,
324343 extra: extra ?? this .extra,
344+ formula: formula ?? this .formula,
325345 );
326346 }
327347}
0 commit comments