@@ -34,7 +34,8 @@ enum VariableType {
3434 image;
3535
3636 /// Returns a string representation of the variable type.
37- String get label => switch (this ) {
37+ String get label =>
38+ switch (this ) {
3839 VariableType .integer => 'Integer' ,
3940 VariableType .text => 'Text' ,
4041 VariableType .decimal => 'Decimal' ,
@@ -55,8 +56,10 @@ enum VariableType {
5556 List () => VariableType .list,
5657 Map () => VariableType .map,
5758 String () => VariableType .text,
58- _ => throw UnsupportedError (
59- 'object type ${obj .runtimeType } is not supported. Cannot determine variable type' ),
59+ _ =>
60+ throw UnsupportedError (
61+ 'object type ${obj
62+ .runtimeType } is not supported. Cannot determine variable type' ),
6063 };
6164 }
6265
@@ -109,13 +112,20 @@ class VariableData
109112 @JsonKey (unknownEnumValue: VariableType .text)
110113 final VariableType type;
111114
115+ /// Extra information that can be stored with the variable. This can be
116+ /// metadata or any other information that is not part of the core variable.
117+ final Map <String , dynamic > extra;
118+
112119 /// Creates a new [VariableData] .
113120 VariableData ({
114121 required this .id,
115122 required this .name,
116123 Object ? value = '' ,
117124 this .type = VariableType .text,
118- }) : value = sanitizeValueForVariableType (value, type).toString ();
125+ Map <String , dynamic >? extra,
126+ })
127+ : value = sanitizeValueForVariableType (value, type).toString (),
128+ extra = extra ?? {};
119129
120130 /// Duplicate a [VariableData] with the given parameters.
121131 VariableData copyWith ({
@@ -125,6 +135,7 @@ class VariableData
125135 VariableType ? type,
126136 bool ? isUsed,
127137 Set <String >? nodes,
138+ Map <String , dynamic >? extra,
128139 }) {
129140 final String ? sanitizedValue = value == null
130141 ? null
@@ -134,6 +145,7 @@ class VariableData
134145 name: name ?? this .name,
135146 value: sanitizedValue ?? this .value,
136147 type: type ?? this .type,
148+ extra: extra ?? this .extra,
137149 );
138150 }
139151
@@ -152,7 +164,8 @@ class VariableData
152164
153165 /// Allows to convert a [VariableData] into [CanvasVariableData] with the
154166 /// given [canvasId] .
155- CanvasVariableData withCanvas (String canvasId) => CanvasVariableData (
167+ CanvasVariableData withCanvas (String canvasId) =>
168+ CanvasVariableData (
156169 id: id,
157170 canvasId: canvasId,
158171 name: name,
@@ -161,7 +174,8 @@ class VariableData
161174 );
162175
163176 /// Returns the value converted to the appropriate type according to [type] .
164- Object ? getValue () => switch (type) {
177+ Object ? getValue () =>
178+ switch (type) {
165179 VariableType .text => value.isEmpty ? null : value,
166180 VariableType .image => value.isEmpty ? null : value,
167181 VariableType .integer => num .tryParse (value).toInt (),
@@ -204,7 +218,7 @@ String? sanitizeValueForVariableType(Object? value, VariableType type) {
204218 final hexMatch = hexColorRegex.firstMatch (value.toString ());
205219 if (hexMatch != null ) return value.toString ().toUpperCase ();
206220 return null ;
207- // This could be a bit expensive. Maybe enable only when required!
221+ // This could be a bit expensive. Maybe enable only when required!
208222 case VariableType .map:
209223 if (value is Map ) return jsonEncode (value);
210224 final map = value.toMap ();
@@ -229,6 +243,7 @@ class CanvasVariableData extends VariableData {
229243 required super .name,
230244 required super .type,
231245 super .value,
246+ super .extra,
232247 });
233248
234249 @override
@@ -240,6 +255,7 @@ class CanvasVariableData extends VariableData {
240255 bool ? isUsed,
241256 String ? canvasId,
242257 Set <String >? nodes,
258+ Map <String , dynamic >? extra,
243259 }) {
244260 final String ? sanitizedValue = value == null
245261 ? null
@@ -250,6 +266,7 @@ class CanvasVariableData extends VariableData {
250266 type: type ?? this .type,
251267 id: id ?? this .id,
252268 canvasId: canvasId ?? this .canvasId,
269+ extra: extra ?? this .extra,
253270 );
254271 }
255272
@@ -262,7 +279,8 @@ class CanvasVariableData extends VariableData {
262279
263280 @override
264281 Map <String , dynamic > toJson () =>
265- _$CanvasVariableDataToJson (this )..remove ('canvasId' );
282+ _$CanvasVariableDataToJson (this )
283+ ..remove ('canvasId' );
266284}
267285
268286/// A variable class that represents creation of a variable from given name.
@@ -283,6 +301,7 @@ class RuntimeVariableData extends VariableData {
283301 required super .name,
284302 super .value = '' ,
285303 super .type = VariableType .text,
304+ super .extra,
286305 }) : super (id: id ?? generateId ());
287306
288307 @override
@@ -293,6 +312,7 @@ class RuntimeVariableData extends VariableData {
293312 VariableType ? type,
294313 bool ? isUsed,
295314 Set <String >? nodes,
315+ Map <String , dynamic >? extra,
296316 }) {
297317 final String ? sanitizedValue = value == null
298318 ? null
@@ -302,6 +322,7 @@ class RuntimeVariableData extends VariableData {
302322 name: name ?? this .name,
303323 value: sanitizedValue ?? this .value,
304324 type: type ?? this .type,
325+ extra: extra ?? this .extra,
305326 );
306327 }
307328}
@@ -350,7 +371,7 @@ class LeafAccessor extends Accessor {
350371 /// Creates a new [LeafAccessor] from an [Accessor] .
351372 LeafAccessor .from (Accessor accessor)
352373 : super (
353- name: accessor.name,
354- type: accessor.type,
355- getValue: accessor.getValue);
374+ name: accessor.name,
375+ type: accessor.type,
376+ getValue: accessor.getValue);
356377}
0 commit comments