updateSp static method

dynamic updateSp(
  1. String key,
  2. dynamic value
)

Update a value in the shared preferences settings

Implementation

static dynamic updateSp(String key, dynamic value) async {
  var prefs = await SharedPreferences.getInstance();
  var persistent = prefs.getString(KEY_EZ_SHARED_PREFERENCES);
  Map<String, dynamic> persistentAsMap;
  if (persistent != null) {
    persistentAsMap = json.decode(persistent);
  } else {
    persistentAsMap = {};
  }
  persistentAsMap[key] = value;
  persistent = json.encode(persistentAsMap);
  await prefs.setString(KEY_EZ_SHARED_PREFERENCES, persistent);
  if (GlobalConfiguration().get(KEY_SP_SETTINGS) != null) {
    GlobalConfiguration().updateValue(KEY_SP_SETTINGS, persistentAsMap);
  } else {
    GlobalConfiguration().addValue(KEY_SP_SETTINGS, persistentAsMap);
  }
  return value;
}