getList<T> static method

List<T>? getList<T>(
  1. String key, [
  2. T from(
    1. Map map
    )?
])

获取数据 //

Implementation

static List<T>? getList<T>(String key, [T from(Map map)?]) {
  final read = GetStorage().read(key);
  if (read == null) {
    XLog.d('没有查询到数据,key=$key');
    return null;
  }
  if (read is List) {
    if (read.isNotEmpty) {
      if (read.first is Map) {
        if (from != null) {
          return read.map((map) => from(map)).toList();
        } else {
          XLog.d('需要将 jsonMap 转为 对象 $T 的 from 函数');
          return null;
        }
      }
      return List.from(read);
    } else {
      return <T>[];
    }
  } else {
    XLog.e('存储的数据不是 List');
    return null;
  }
}