Skip to content
pubscout

hive_generator

2.0.1, released 3 years ago by hivedb.dev

Generates Hive TypeAdapter code for Dart classes automatically.

Quiet but busy
$ flutter pub add hive_generator
Source repository

What it does

The package scans annotated classes and creates the boiler‑plate TypeAdapter needed by Hive to serialize and deserialize objects. It integrates with build_runner to produce Dart files during build time.

AI-written summary of version 2.0.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need type‑safe, performant local storage with Hive and want to avoid writing adapters manually
  • You are already using Hive and want a zero‑maintenance way to keep adapters in sync with model changes

Skip it when

  • You prefer a runtime reflection‑based solution instead of code generation
  • Your project does not use Hive for storage

Strengths

  • Eliminates manual adapter boiler‑plate
  • Supports null‑safety, inheritance, default values, and various field types
  • Works with build_runner and stays up‑to‑date with Hive versions

Weaknesses

  • Requires build_runner step in CI/build process
  • Only works with Hive; not a generic serialization solution

Setup

Kind
Pure Dart
Effort
Low
Code generation
Yes (build_runner)
Direct dependencies
5

Add hive_generator and build_runner to dev_dependencies, annotate classes with @HiveType/@HiveField, then run `flutter pub run build_runner build`.

import 'package:hive/hive.dart';
import 'package:hive_generator/hive_generator.dart';

part 'person.g.dart';

@HiveType(typeId: 0)
class Person {
  @HiveField(0)
  final String name;
  @HiveField(1)
  final int age;

  Person(this.name, this.age);
}
// Run build_runner to generate person.g.dart with the adapter

Alternatives

Packages that do the same job and could replace hive_generator.

Works with

Packages commonly used together with hive_generator: ones it builds on, ones built on it, and its own family.