readCollection<T> static method

Future<List<T>> readCollection<T>(
  1. String key, {
  2. Map<Type, dynamic>? modelDecoders,
})

Read the collection values using a key.

Implementation

static Future<List<T>> readCollection<T>(String key,
    {Map<Type, dynamic>? modelDecoders}) async {
  String? data = await read(key);
  if (data == null || data == "") return [];

  List<dynamic> listData = jsonDecode(data);

  if (!["dynamic", "string", "double", "int"]
      .contains(T.toString().toLowerCase())) {
    return List.from(listData)
        .map((json) =>
            dataToModel<T>(data: json, modelDecoders: modelDecoders))
        .toList();
  }
  return List.from(listData).toList().cast();
}