valueEnsureAsList<T> static method
Implementation
static List<T> valueEnsureAsList<T>(Object? value) {
if (value is List<T>) return value;
try {
final valueList = value as List;
if (!_isDynamic<T>()) {
if (_isMap<T>()) {
return valueList
.map((e) {
if (e is T) return e;
return Map.from(e);
})
.toList()
.cast<T>();
}
if (_isMapStringDynamic<T>()) {
return valueList
.map((e) {
if (e is T) return e;
return Map<String, dynamic>.from(e);
})
.toList()
.cast<T>();
}
if (_isMapStringString<T>()) {
return valueList
.map((e) {
if (e is T) return e;
return Map<String, String>.from(e);
})
.toList()
.cast<T>();
}
}
return List<T>.from(value);
} catch (_) {
throw JSONHelperException("Failed to parse object as list<$T>");
}
}