get method

Future get(
  1. String key
)

Retrieves the value for a given key from SharedPreferences.

This method will automatically return the correct type (int, bool, double, string, or string list) based on the provided key. If the key does not exist, the method throws an exception.

  • key: The key for the value to be retrieved.

Implementation

Future<dynamic> get(String key) async {
  await ensureSharedPrefIsInitialized();
  if (intKeys.containsKey(key)) {
    return getInt(key);
  } else if (boolKeys.containsKey(key)) {
    return getBool(key);
  } else if (doubleKeys.containsKey(key)) {
    return getDouble(key);
  } else if (stringKeys.containsKey(key)) {
    return getString(key);
  } else if (stringListKeys.containsKey(key)) {
    return getStringList(key);
  } else {
    throw Exception("Key '$key' is not implemented.");
  }
}