decode method

  1. @override
DateTime? decode(
  1. String? base64
)
override

Decodes a value of storage type TStore back to type T.

Returns null if the stored value is null or cannot be decoded.

Implementation

@override
DateTime? decode(String? base64) {
  if (base64 == null) return null;
  try {
    final bytes = base64Decode(base64);
    if (bytes.length < 8) return null; // Too short to contain a timestamp
    final micros = ByteData.sublistView(bytes).getInt64(0, Endian.big);
    return DateTime.fromMicrosecondsSinceEpoch(micros);
  } catch (_) {
    return null;
  }
}