getDuration method

  1. @override
Future<Duration?> getDuration(
  1. String key
)
override

Retrieves a Duration value by its key.

This method fetches a Duration value previously stored using setDuration. The Duration is stored as milliseconds and reconstructed when retrieved. If no value exists for the given key, or the stored value cannot be parsed as a Duration, this method returns null.

Parameters:

  • key - The unique identifier of the Duration value to retrieve.

Returns a Future that completes with the stored Duration value if found, or null if the key doesn't exist or the value cannot be parsed as a Duration.

Throws:

Implementation

@override
Future<Duration?> getDuration(String key) async {
  validateKey(key);
  final int? millis = await backend.getInt(encodeKey(key));
  if (millis == null) return null;
  return Duration(milliseconds: millis);
}