customObjectsFromPin<T> static method
Implementation
static Future<List<T>> customObjectsFromPin<T>(String classname,
FutureOr<T> Function(Map<String, dynamic> json) fromJson) async {
List<T> objectList = [];
SharedPreferences prefs = await SharedPreferences.getInstance();
String? objectsJson = prefs.getString(classname);
if (objectsJson != null) {
List<String> objectJsonList = objectsJson.split(';');
if (objectJsonList.isNotEmpty) {
// Remove last because split create at last one element = ""
objectJsonList.removeLast();
}
for (String objectJson in objectJsonList) {
var json = jsonDecode(objectJson);
var obj = await fromJson(json);
objectList.add(obj);
}
}
return objectList;
}