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;
try {
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>();
}
if (_isListOfListInt()) {
return value
.map((e) => valueEnsureAsList<List<int>>(e))
.toList()
.cast<T>();
}
return value.map((e) => valueAs<T>(e)).toList();
}
} catch (_) {}
return List<T>.from(value);
} catch (e) {
throw JsonParserError(
"Failed to parse object as list<$T>",
details: {"error": e.toString()},
);
}
}