bosc_flutter_loacl_storage_package (1.1.0)
Published 2026-02-13 06:38:00 +00:00 by mansi.kansara
Installation
dart pub add bosc_flutter_loacl_storage_package:1.1.0 --hosted-url=About this package
Type-safe local storage for Flutter using GetStorage.
BOSC Flutter Local Storage
Type-safe local storage for Flutter using GetStorage. Supports primitives, custom objects (via serializers), optional encryption, batch operations, and change streams.
Installation
dependencies:
bosc_flutter_loacl_storage_package: ^1.1.0
flutter pub get
Quick Start
import 'package:bosc_flutter_loacl_storage_package/bosc_flutter_loacl_storage_package.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await LocalStorageClient.instance.initialize();
runApp(MyApp());
}
// In your app
final storage = LocalStorageClient.instance;
await storage.write<String>(StorageKeys.authToken, 'abc123');
await storage.write<int>(StorageKeys.userId, 12345);
final token = storage.read<String>(StorageKeys.authToken);
final userId = storage.read<int>(StorageKeys.userId, defaultValue: 0);
await storage.remove(StorageKeys.authToken);
await storage.clear();
Configuration
// Development (logging on)
final storage = LocalStorageClient(
config: StorageConfig.development(boxName: 'dev_storage'),
);
// Production
final storage = LocalStorageClient(
config: StorageConfig.production(boxName: 'prod_storage', enableAutoBackup: true),
);
// Testing (isolated box)
final storage = LocalStorageClient.test();
Custom Objects
StorageSerializer.register<User>(
serializer: (user) => user.toJson(),
deserializer: (json) => User.fromJson(json),
);
await storage.write<User>(StorageKeys.userProfile, user);
final user = storage.read<User>(StorageKeys.userProfile);
Encryption
final storage = LocalStorageClient(
encryptionHandler: MyEncryptionHandler('secret_key'),
);
await storage.writeEncrypted(StorageKeys.authToken, 'sensitive');
final token = storage.read<String>(StorageKeys.authToken); // decrypts automatically
Batch & Reactive
await storage.writeBatch({
StorageKeys.userId: 123,
StorageKeys.userName: 'John',
StorageKeys.isDarkMode: true,
});
storage.listen<String>(StorageKeys.authToken).listen((token) {
print('Token changed: $token');
});
Backup / Restore
final backup = storage.createBackup();
await storage.restoreBackup(backup);
final jsonBackup = storage.exportToJson();
await storage.importFromJson(jsonBackup);
Testing
final storage = LocalStorageClient.test();
await storage.initialize();
await storage.write<String>('key', 'value');
expect(storage.read<String>('key'), 'value');
await storage.clear();
storage.dispose();
API Summary
| Operation | Methods |
|---|---|
| Write | write, writeEncrypted, writeBatch |
| Read | read, readRequired, readOrWrite |
| Query | containsKey, getKeys, getAll, isEmpty, length |
| Delete | remove, removeAll, clear, clearAuthData |
| Reactive | listen<T>(key) |
| Backup | createBackup, restoreBackup, exportToJson, importFromJson |
Exceptions
StorageException (base), StorageInitializationException, StorageReadException, StorageWriteException, StorageDeleteException, StorageClearException, StorageSerializationException, StorageEncryptionException. Use read(key, defaultValue: x) to avoid throws for missing keys.
License
MIT. See LICENSE. Changes: CHANGELOG.md.
Details
2026-02-13 06:38:00 +00:00
Assets (1)
Versions (2)
View all
Pub
6
29 KiB
1.1.0.tar.gz
29 KiB