juice_storage 0.8.0 copy "juice_storage: ^0.8.0" to clipboard
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.

example/lib/main.dart

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',
          ),
        ],
      ),
    );
  }
}
1
likes
100
points
171
downloads

Publisher

unverified uploader

Weekly Downloads

Local storage, caching, and secure storage for the Juice framework. Supports Hive, SharedPreferences, SQLite, and flutter_secure_storage.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#storage #cache #hive #sqlite #bloc

Documentation

API reference

Funding

Consider supporting this project:

github.com

License

MIT (license)

Dependencies

flutter, flutter_secure_storage, hive, hive_flutter, juice, path, shared_preferences, sqflite

More

Packages that depend on juice_storage