hive_generator
2.0.1, released 3 years ago by hivedb.dev
Generates Hive TypeAdapter code for Dart classes automatically.
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 adapterAlternatives
Packages that do the same job and could replace hive_generator.
- json_serializable
Automatically generate code for converting Dart classes to and from JSON.
94Compare - copy_with_extension_gen
Generate type‑safe copyWith extensions for annotated classes and record typedefs.
85Compare - supadart
CLI tool that generates type-safe Dart and Flutter classes from your Supabase database schema.
63Compare - icon_font_generator
Converts SVG icons to OpenType fonts and generates Flutter-compatible icon classes.
60Compare
Works with
Packages commonly used together with hive_generator: ones it builds on, ones built on it, and its own family.
- analyzerhive_generator depends on itPerforms static analysis of Dart code for tool integration and embedding.
- buildhive_generator depends on itPackage for authoring build_runner compatible code generators.
- source_genhive_generator depends on itSource code generation builders and utilities for the Dart build system.
- source_helperhive_generator depends on itUtilities to help with Dart source code generation and string literal formatting.
- hivehive_generator depends on itFast, pure Dart key-value store with optional AES-256 encryption
- build_runnerUsed togetherA build system for Dart code generation and modular compilation.
- hive_flutterSame familyFlutter extension for Hive providing easy initialization and adapters for common types.