hive_ce_flutter 2.1.0 copy "hive_ce_flutter: ^2.1.0" to clipboard
hive_ce_flutter: ^2.1.0 copied to clipboard

Extension for Hive. Makes it easier to use Hive in Flutter apps.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:hive_ce_flutter/hive_flutter.dart';

const counterBox = 'counter';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Hive.initFlutter();
  final box = await Hive.openBox(counterBox);
  if (box.isEmpty) {
    await box.add(0);
  }
  runApp(const MaterialApp(home: HiveCounterApp()));
}

class HiveCounterApp extends StatelessWidget {
  const HiveCounterApp({super.key});

  @override
  Widget build(BuildContext context) {
    final box = Hive.box(counterBox);

    return Scaffold(
      appBar: AppBar(title: const Text('Hive CE Example')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text('You have pushed the button this many times:'),
            ValueListenableBuilder(
              valueListenable: box.listenable(),
              builder: (context, box, widget) {
                return Text(
                  box.getAt(0).toString(),
                  style: Theme.of(context).textTheme.headlineMedium,
                );
              },
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => box.putAt(0, box.getAt(0) + 1),
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}
7
likes
160
pub points
92%
popularity

Publisher

verified publisheriodesignteam.com

Extension for Hive. Makes it easier to use Hive in Flutter apps.

Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

Apache-2.0 (license)

Dependencies

flutter, hive_ce, path, path_provider

More

Packages that depend on hive_ce_flutter