SecureStorage class
The singleton service for persisting sensitive authentication data using the device's secure storage (Keychain on iOS, EncryptedSharedPreferences on Android).
Storage keys are loaded from the environment file via flutter_dotenv to
keep them out of source code. All read and write methods handle errors
gracefully — corrupted data is cleared automatically and failures are
logged through AppLogger so the app can recover without crashing.
Access the shared instance via SecureStorage.instance.
// Persist tokens after login.
await SecureStorage.instance.setAuthTokenModel(tokens);
// Retrieve tokens — returns null when absent or corrupted.
final tokens = await SecureStorage.instance.getAuthTokenModel();
if (tokens != null && !tokens.isTokenExpired) {
// Proceed with authenticated request.
}
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- storage → FlutterSecureStorage
-
The underlying FlutterSecureStorage instance used for all read and write
operations.
final
Methods
-
deleteAuthTokenModelData(
) → Future< void> - Deletes the stored authentication token from secure storage.
-
deleteUserModelData(
) → Future< void> - Deletes the stored user model from secure storage.
-
getAuthTokenModel(
) → Future< AuthTokenModel?> -
The AuthTokenModel currently stored in secure storage, or
nullif absent, empty, or corrupted. -
getUserModel(
) → Future< UserModel?> -
The UserModel currently stored in secure storage, or
nullif absent, empty, or corrupted. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setAuthTokenModel(
AuthTokenModel authTokenModel) → Future< void> -
Serialises
authTokenModelto JSON and writes it to secure storage, overwriting any previously stored token. -
setUserModel(
UserModel userModel) → Future< void> -
Serialises
userModelto JSON and writes it to secure storage, overwriting any previously stored user. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → SecureStorage
-
The shared SecureStorage instance used throughout the application.
no setter