decode method

  1. @override
List<bool>? decode(
  1. String? base64String
)
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
List<bool>? decode(String? base64String) {
  if (base64String == null) return null;
  try {
    final bytes = base64Decode(base64String);
    if (bytes.length < 4) return null; // too short to have length

    final length = ByteData.sublistView(bytes, 0, 4).getUint32(0, Endian.big);
    final result = <bool>[];

    for (var i = 4; i < bytes.length; i++) {
      final byte = bytes[i];
      for (var bit = 0; bit < 8; bit++) {
        result.add((byte & (1 << bit)) != 0);
      }
    }
    if (result.length > length) {
      result.length = length; // truncate any extra padding
    }
    return result;
  } catch (_) {
    return null;
  }
}