set<T> static method

Future<bool> set<T>(
  1. String key,
  2. T value
)

Implementation

static Future<bool> set<T>(String key, T value) {
  if (_preferences == null) {
    debugPrint('StorageUtil, need call await init() first');
    return Future.value(false);
  }

  String type = value.runtimeType.toString();
  switch (type) {
    case "String":
      return _preferences!.setString(key, value as String);
    case "int":
      return _preferences!.setInt(key, value as int);
    case "bool":
      return _preferences!.setBool(key, value as bool);
    case "double":
      return _preferences!.setDouble(key, value as double);
    case "List<String>":
      return _preferences!.setStringList(key, value as List<String>);
    case "_InternalLinkedHashMap<String, String>":
      return _preferences!.setString(key, json.encode(value));
    default:
      return Future.value(false);
  }
}