flutterfire_gen
0.6.0, released 6 months ago by kosukesaigusa.com
Generates type‑safe CRUD code for Cloud Firestore documents in Flutter.
What it does
flutterfire_gen reads Dart classes annotated with @FirestoreDocument and produces query and model helpers for reading, creating, updating, and deleting Firestore documents. It handles default values, server timestamps, and FieldValue operations automatically.
AI-written summary of version 0.6.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need compile‑time, type‑safe Firestore access without writing boilerplate.
- You want automatic handling of server timestamps and FieldValue operations.
- You prefer a single source of truth for document schema in Dart.
Skip it when
- You only need runtime Firestore access and prefer a lightweight wrapper.
- Your project targets non‑Flutter platforms only.
Strengths
- Eliminates repetitive Firestore CRUD code
- Ensures compile‑time type safety
- Supports default values and FieldValue annotations
Weaknesses
- Requires build_runner and code‑gen step
- Breaks on major version bumps of analyzer/source_gen
- Tied to specific Firestore schema annotations
Setup
- Kind
- Flutter widgets
- Effort
- Medium
- Code generation
- Yes (build_runner)
- Direct dependencies
- 10
Add flutterfire_gen, flutterfire_gen_annotation, flutterfire_gen_utils to dev_dependencies, run build_runner, include part file in source.
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutterfire_gen_annotation/flutterfire_gen_annotation.dart';
part 'todo.flutterfire_gen.dart';
@FirestoreDocument(path: 'todos/{todoId}')
class Todo {
const Todo({required this.title, required this.isCompleted, this.createdAt, this.updatedAt});
final String title;
@ReadDefault(false)
@CreateDefault(false)
final bool isCompleted;
@alwaysUseFieldValueServerTimestampWhenCreating
final DateTime? createdAt;
@alwaysUseFieldValueServerTimestampWhenCreating
@alwaysUseFieldValueServerTimestampWhenUpdating
final DateTime? updatedAt;
}
// After running build_runner, use TodoQuery to fetch or add documents.
Alternatives
Packages that do the same job and could replace flutterfire_gen.
- built_value
Provides code‑gen for immutable models and serialization without Firestore‑specific helpers.
88Compare - freezed_annotation
Generates immutable data classes and unions; can be combined with custom Firestore wrappers.
78Compare
Works with
Packages commonly used together with flutterfire_gen: ones it builds on, ones built on it, and its own family.
- analyzerflutterfire_gen depends on itPerforms static analysis of Dart code for tool integration and embedding.
- dart_styleflutterfire_gen depends on itProvides an API and CLI to format Dart source code automatically.
- json_annotationflutterfire_gen depends on itProvides annotations for json_serializable to generate JSON (de)serialization code.
- buildflutterfire_gen depends on itPackage for authoring build_runner compatible code generators.
- source_genflutterfire_gen depends on itSource code generation builders and utilities for the Dart build system.
- cloud_firestoreflutterfire_gen depends on itFlutter plugin for Cloud Firestore noSQL database with live synchronization.
- build_runnerUsed togetherA build system for Dart code generation and modular compilation.