Skip to content

Commit ae25a12

Browse files
committed
Implement VariableType.fromObject constructor.
1 parent 931eec8 commit ae25a12

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

lib/src/api/models/variables_model.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,41 @@ enum VariableType {
4040
VariableType.list => 'List',
4141
VariableType.map => 'Map',
4242
};
43+
44+
factory VariableType.fromObjectType(Object obj) {
45+
return switch (obj) {
46+
int() => VariableType.integer,
47+
double() => VariableType.decimal,
48+
bool() => VariableType.boolean,
49+
ColorRGBA() => VariableType.color,
50+
ColorRGB() => VariableType.color,
51+
List() => VariableType.list,
52+
Map() => VariableType.map,
53+
_ => throw UnsupportedError(
54+
'object type ${obj.runtimeType} is not supported. Cannot determine variable type'),
55+
};
56+
}
57+
58+
/// Whether the variable type is [VariableType.map].
59+
bool get isMap => this == VariableType.map;
60+
61+
/// Whether the variable type is [VariableType.list].
62+
bool get isList => this == VariableType.list;
63+
64+
/// Whether the variable type is [VariableType.color].
65+
bool get isColor => this == VariableType.color;
66+
67+
/// Whether the variable type is [VariableType.boolean].
68+
bool get isBoolean => this == VariableType.boolean;
69+
70+
/// Whether the variable type is [VariableType.decimal].
71+
bool get isDecimal => this == VariableType.decimal;
72+
73+
/// Whether the variable type is [VariableType.integer].
74+
bool get isInteger => this == VariableType.integer;
75+
76+
/// Whether the variable type is [VariableType.text].
77+
bool get isText => this == VariableType.text;
4378
}
4479

4580
/// Store information of a variable. [id] must not be empty when creating a

0 commit comments

Comments
 (0)