getDateTime method
Retrieves a DateTime value by its key.
This method fetches a DateTime value previously stored using setDateTime.
The DateTime is stored as an ISO 8601 string and reconstructed when
retrieved. If no value exists for the given key, or the stored value cannot
be parsed as a DateTime, this method returns null.
Parameters:
key- The unique identifier of the DateTime value to retrieve.isUtc- Optional. Iftrue, the returned DateTime will be in UTC timezone. Iffalse(default), it will be in the local timezone.
Returns a Future that completes with the stored DateTime value if found,
or null if the key doesn't exist or the value cannot be parsed as a
DateTime.
Throws:
- ArgumentError if the key is invalid.
Implementation
@override
Future<DateTime?> getDateTime(String key, {bool isUtc = false}) async {
validateKey(key);
final int? millis = await backend.getInt(encodeKey(key));
if (millis == null) return null;
final DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(millis, isUtc: true);
return isUtc ? dateTime : dateTime.toLocal();
}