File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed
Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,9 @@ class VariableData
6161 /// explicitly provided by the user.
6262 final String value;
6363
64+ /// Whether the variable has a value or not.
65+ bool get hasValue => value.isNotEmpty;
66+
6467 @JsonKey (unknownEnumValue: VariableType .text)
6568
6669 /// Type of the variable. This is used to determine how to parse the value.
@@ -113,10 +116,17 @@ class VariableData
113116 type: type,
114117 );
115118
116- /// Converts [value] to given type [T] . This will fail if type conversion
117- /// fails.
118- R ? typedValue <R extends Object >({R ? defaultValue}) =>
119- value.typedValue <R >(defaultValue: defaultValue);
119+ /// Returns the value converted to the appropriate type according to [type] .
120+ Object ? getValue () {
121+ return switch (type) {
122+ VariableType .text => value,
123+ VariableType .integer => num .tryParse (value).toInt (),
124+ VariableType .decimal => num .tryParse (value).toDouble (),
125+ VariableType .boolean => bool .tryParse (value, caseSensitive: false ),
126+ VariableType .map => tryJsonDecode (value),
127+ VariableType .list => value.toList (),
128+ };
129+ }
120130}
121131
122132/// Contains all the variables associated with a canvas inside a page.
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ extension ObjectExt on Object? {
88 /// Returns [defaultValue] or null otherwise.
99 R ? typedValue <R extends Object >({R ? defaultValue}) {
1010 final value = this ;
11- if (this == null ) return defaultValue;
11+ if (this == null ) return defaultValue;
1212 if (value is R ) return value;
1313
1414 return switch (R ) {
@@ -155,7 +155,7 @@ extension ConversionExt on Object? {
155155 if (value is double ) return value != 0 ;
156156 if (value is num ) return value != 0 ;
157157 if (value is String ) {
158- final parsedBool = bool .tryParse (value. toLowerCase () );
158+ final parsedBool = bool .tryParse (value, caseSensitive : false );
159159 if (parsedBool != null ) return parsedBool;
160160 final parsedNum = num .tryParse (value);
161161 if (parsedNum != null ) return parsedNum != 0 ;
You can’t perform that action at this time.
0 commit comments