getValue<T> method

T? getValue<T>({
  1. required dynamic key,
})

Retrieves a value from the shared preferences based on the provided key.

Returns the value if it exists, otherwise returns null.

The key parameter represents the key associated with the value to retrieve from shared preferences.

Example:

String? username = SimpleSharedPref().getValue<String>('username');

Implementation

T? getValue<T>({required dynamic key}) {
  try {
    if (_preferences!.containsKey(key.toString())) {
      var value = _preferences!.get(key.toString());
      // if (_cryptoModule != null && value is String) {
      //   return _cryptoModule!.decryptData(value) as T?;
      // }
      return value as T?;
    }
  } catch (e) {
    _logException('Error while getting value from shared preferences',
        error: e);
  }
  return null;
}