setMapData<T> static method

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

设置Map类型到缓存中去, cast 是否强制转换,强制转换成字符串有可能会转换的不完整

Implementation

static Future<bool> setMapData<T>(String key, T value,
    {bool cast = false}) async {
  if (_prefs == null) await getInstance();
  String newValue = cast ? value.toString() : json.encode(value);
  return await _prefs?.setString(key, newValue) as bool;
}