Secure class

Annotates a field to be stored securely via FlutterSecureStorage.

Best for: Bearer tokens, API credentials, and PII (Personally Identifiable Information). Security: Uses Keychain (iOS), KeyStore (Android), and SecretService/libsecret (Linux).

Deep Implementation Detail

Unlike SharedPreferences, secure storage operations are asynchronous by nature in the underlying OS. The generated system handles this by providing immediate in-memory reactive access via ValueNotifier, while the persistence to disk happens in the background.

Complex Scenario: Token Refresh

@GeneratePreferences()
class SecurePrefs extends BasePreferences with _$SecurePrefs {
  @Secure('jwt_token')
  late final String? _token;
}

Constructors

Secure(String key)
const

Properties

hashCode int
The hash code for this object.
no setterinherited
key String
The unique key for the secure entry.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited