setListData<T> static method

Future<bool> setListData<T>(
  1. String key,
  2. List<T> value, {
  3. bool cast = false,
})

设置list类型到缓存中去

cast 是否强制转换,强制转换成字符串有可能会转换的不完整

Implementation

static Future<bool> setListData<T>(String key, List<T> value,
    {bool cast = false}) async {
  if (_prefs == null) await getInstance();
  List<String> dataList = value.map((v) {
    return cast ? v.toString() : json.encode(v);
  }).toList();
  return await _prefs?.setStringList(key, dataList) as bool;
}