hive initialisation

PHOTO EMBED

Wed Oct 11 2023 08:13:18 GMT+0000 (Coordinated Universal Time)

Saved by @Frankocitello #flutter

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Hive Tutorial',
      home: FutureBuilder(
        future: Hive.openBox('contacts'),
        builder: (context, snapshot) {
          if (snapshot.connectionState == ConnectionState.done) {
            if (snapshot.hasError)
              return Text(snapshot.error.toString());
            else
              return ContactPage();
          }
          // Although opening a Box takes a very short time,
          // we still need to return something before the Future completes.
          else
            return Scaffold();
        },
      ),
    );
  }

  @override
  void dispose() {
    Hive.close();
    super.dispose();
  }
}
content_copyCOPY

https://resocoder.com/2019/09/30/hive-flutter-tutorial-lightweight-fast-database/