Hive introduction
You can find everything here https://pub.dev/packages/hive
Steps
From Visual Studio Code
Cmd + Shift + PtoAdd dependencythen search forhive_flutter.From Visual Studio Code
Cmd + Shift + PtoAdd Dev dependencythen search forbuild_runnerandhive_generator.Mark the model as
HiveTypeand importpart [model_name].g.dartto generate the adapter in the next step.import 'package:hive_flutter/hive_flutter.dart'; part 'model.g.dart'; @HiveType(typeId: 0) class YourModel { @HiveField(0) final String property1; @HiveField(1) final String property2; YourModel(this.property1, this.property2); }From the terminal, run
dart run build_runner buildto generate the HiveAdapter.Initialize HiveBox, register adapters(if any), and open the box with its name.
await Hive.initFlutter(); Hive.registerAdapter(YourModelAdapter()); await Hive.openBox('BoxName');Get the box by its name and it’s ready to use.
final box = Hive.box('BoxName');