unified_local_data 2.0.0
unified_local_data: ^2.0.0 copied to clipboard
Engine-agnostic local storage for Flutter. One API over Hive, Isar or your own engine, with typed objects, queries, reactive streams and transactions.
import 'package:flutter/material.dart';
import 'package:unified_local_data/unified_local_data.dart';
import 'package:path_provider/path_provider.dart';
/// A simple example demonstrating how to use [unified_local_data] with the
/// Hive CE engine.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize the data source with the Hive engine.
final dir = await getApplicationDocumentsDirectory();
final dataSource = await UnifiedDataSourceFactory.create(
UnifiedDataSourceConfig.hive(
directory: dir.path,
preloadBoxes: ['settings', 'cache'],
),
);
// Put a simple string value.
await dataSource.put<String>('settings', 'theme', 'dark');
// Read it back.
final String? theme = await dataSource.get<String>('settings', 'theme');
debugPrint('Stored theme: $theme'); // Stored theme: dark
}