Code generator for creating helper functions for registering Hive types. It will generate method named registerAdapters with all the hive adapters for the types annotated with @HiveType.
Add the following to your pubspec.yaml file:
dev_dependencies:
hive_generator: latest
type_register: latest
dart run build_runner build -d
By default it will generate a file named register_adapters.dart
inside lib folder.
if you want to change the output location create build.yaml
file in the root of your project and add the following:
targets:
$default:
builders:
type_register|type_register:
options:
output_path: lib/src/core/
register_adapters.dart
import 'package:example/another_model.dart';
import 'package:example/model.dart';
import 'package:hive_local_storage/hive_local_storage.dart';
void registerAdapters() {
Hive..registerAdapter<AnotherModel>(AnotherModelAdapter())
..registerAdapter<Model>(ModelAdapter());
}