parseId<T> static method
T
parseId<T>(
- dynamic id
Transforms an id
(whether it is a String, num, etc.) into one acceptable by a service.
The single type argument, T
, is used to determine how to parse the id
.
For example, parseId<bool>
attempts to parse the value as a bool.
Implementation
static T parseId<T>(id) {
if (id == null || id == 'null') {
return 'null' as T;
//throw ArgumentError("[Service] Null is not supported");
} else if (T == String) {
return id.toString() as T;
} else if (T == int) {
return int.parse(id.toString()) as T;
} else if (T == bool) {
return (id == true || id.toString() == 'true') as T;
} else if (T == double) {
return double.parse(id.toString()) as T;
} else if (T == num) {
return num.parse(id.toString()) as T;
} else {
return id as T;
}
}