stringToIterable<T> function
Null safety
Generates an Iterable of a specified conversion way by toElement
from a String with a json array structure
Example:
String array = '[1,2]'
List<int> list = stringToIterable(array, (element) => int.parse(element)).toList();
Implementation
Iterable<T> stringToIterable<T>(
final String value,
final T Function(String e) toElement,
) {
return value
.replaceAll("[", "")
.replaceAll("]", "")
.split(",")
.map<T>(toElement);
}