SecureStorageService class
SecureStorageService
Type-safe wrapper around flutter_secure_storage for sensitive data.
USE THIS FOR: tokens, credentials, session data, any sensitive value. USE StorageService (SharedPreferences) FOR: settings, preferences, non-sensitive flags.
iOS: Data stored in Keychain. Supports keychain groups for cross-app sharing. Android: AES-256 encrypted via EncryptedSharedPreferences.
TWO WAYS TO USE:
await SecureStorageService.init();
SecureStorageService.instance.setString('key', 'value');
- Scoped instance via withOptions — when you need separate storage configurations (e.g. merkado_auth needs a shared scope AND a local scope):
final sharedStorage = SecureStorageService.withOptions(
iOSOptions: IOSOptions(groupId: 'com.grascope.sharedauth'),
androidOptions: AndroidOptions(sharedPreferencesName: 'grascope_shared'),
);
Constructors
- SecureStorageService.withOptions({IOSOptions iOSOptions = const IOSOptions(accessibility: KeychainAccessibility.first_unlock), AndroidOptions androidOptions = const AndroidOptions()})
-
Create a scoped instance with custom storage options.
factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
clear(
) → Future< void> - ⚠️ Deletes ALL keys in this storage instance. On the singleton, this includes all app data. On a scoped instance, only that scope's data is cleared.
-
containsKey(
String key) → Future< bool> -
getAllKeys(
) → Future< Set< String> > -
getBool(
String key) → Future< bool?> -
getBoolOrDefault(
String key, bool defaultValue) → Future< bool> -
getInt(
String key) → Future< int?> -
getIntOrDefault(
String key, int defaultValue) → Future< int> -
getJson(
String key) → Future< Map< String, dynamic> ?> -
getJsonList(
String key) → Future< List< Map< ?>String, dynamic> > -
getString(
String key) → Future< String?> -
getStringOrDefault(
String key, String defaultValue) → Future< String> -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
String key) → Future< void> -
removeBatch(
List< String> keys) → Future<void> -
setBatch(
Map< String, dynamic> values) → Future<void> -
setBool(
String key, bool value) → Future< void> -
setInt(
String key, int value) → Future< void> -
setJson(
String key, Map< String, dynamic> value) → Future<void> -
setJsonList(
String key, List< Map< value) → Future<String, dynamic> >void> -
setString(
String key, String value) → Future< void> -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → SecureStorageService
-
The app-wide singleton instance.
Only available after init has been called.
no setter