getString method

Future<String> getString(
  1. String key
)

Retrieves a string value from SharedPreferences.

Returns the default value if the key does not exist.

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

Implementation

Future<String> getString(String key) async {
  await ensureSharedPrefIsInitialized();
  if (stringKeys.containsKey(key)) {
    return prefs.getString(key) ?? stringKeys[key]!;
  } else {
    throw Exception("Key '$key' is not implemented as string.");
  }
}