get method

  1. @override
dynamic get(
  1. dynamic key
)
override

Retrieves the value stored under the given key.

  • key: The key for the stored data.

Returns the decoded value if found, otherwise null.

Implementation

@override
dynamic get(dynamic key) {
  try {
    if (key == null) {
      return null;
    }

    // Retrieve the encoded value from storage.
    final encodedValue = storage.get(key);

    // If value is not found or is not a string, return it as is.
    if (encodedValue == null || encodedValue is! String) {
      return encodedValue;
    }

    // Decode the JSON-encoded value before returning.
    final value = json.decode(encodedValue);
    return value;
  } catch (e) {
    debugPrint(e.toString());
    return null;
  }
}