juice_storage 0.8.0
juice_storage: ^0.8.0 copied to clipboard
Local storage, caching, and secure storage for the Juice framework. Supports Hive, SharedPreferences, SQLite, and flutter_secure_storage.
import 'package:juice/juice.dart';
import 'package:juice_storage/juice_storage.dart';
import 'blocs/arcade_demo_bloc.dart';
import 'screens/arcade_screen.dart';
import 'screens/inspector_screen.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
// Register StorageBloc as a permanent bloc
if (!BlocScope.isRegistered<StorageBloc>()) {
BlocScope.register<StorageBloc>(
() => StorageBloc(
config: const StorageConfig(
prefsKeyPrefix: 'arcade_',
hiveBoxesToOpen: ['arcade_box'],
sqliteDatabaseName: 'arcade.db',
enableBackgroundCleanup: true,
cacheCleanupInterval: Duration(seconds: 1), // Fast cleanup for demo
),
),
lifecycle: BlocLifecycle.permanent,
);
}
// Initialize storage before running app
final storage = BlocScope.get<StorageBloc>();
await storage.initialize();
// Register ArcadeDemoBloc as leased (lives with Arcade screen)
// Uses BlocScope.get<StorageBloc>() internally for cross-bloc communication
if (!BlocScope.isRegistered<ArcadeDemoBloc>()) {
BlocScope.register<ArcadeDemoBloc>(
() => ArcadeDemoBloc(),
lifecycle: BlocLifecycle.leased,
);
}
runApp(const StorageArcadeApp());
}
class StorageArcadeApp extends StatelessWidget {
const StorageArcadeApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Storage Arcade',
debugShowCheckedModeBanner: false,
theme: ThemeData(
useMaterial3: true,
colorSchemeSeed: Colors.deepPurple,
brightness: Brightness.light,
),
darkTheme: ThemeData(
useMaterial3: true,
colorSchemeSeed: Colors.deepPurple,
brightness: Brightness.dark,
),
home: const _Home(),
);
}
}
class _Home extends StatefulWidget {
const _Home();
@override
State<_Home> createState() => _HomeState();
}
class _HomeState extends State<_Home> {
int _index = 0;
@override
Widget build(BuildContext context) {
final pages = [
ArcadeScreen(),
InspectorScreen(),
];
return Scaffold(
body: IndexedStack(
index: _index,
children: pages,
),
bottomNavigationBar: NavigationBar(
selectedIndex: _index,
onDestinationSelected: (i) => setState(() => _index = i),
destinations: const [
NavigationDestination(
icon: Icon(Icons.timer_outlined),
selectedIcon: Icon(Icons.timer),
label: 'Arcade',
),
NavigationDestination(
icon: Icon(Icons.monitor_heart_outlined),
selectedIcon: Icon(Icons.monitor_heart),
label: 'Inspector',
),
],
),
);
}
}