PrfBytes constructor

PrfBytes(
  1. String key, {
  2. Uint8List? defaultValue,
})

Creates a new bytes preference variable with the specified key.

The optional defaultValue is returned if the preference is not found or if an error occurs while reading.

Implementation

PrfBytes(super.key, {super.defaultValue})
    : super(
        from: (base64) {
          if (base64 == null) return null;
          try {
            return base64Decode(base64);
          } catch (_) {
            return null; // corrupted or invalid base64
          }
        },
        to: (value) => base64Encode(value),
        getter: (prefs, key) async => prefs.getString(key),
        setter: (prefs, key, value) async => prefs.setString(key, value),
      );