Skip to content
pubscout

flutterfire_gen

0.6.0, released 6 months ago by kosukesaigusa.com

Generates type‑safe CRUD code for Cloud Firestore documents in Flutter.

$ flutter pub add flutterfire_gen
Source repository

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.

  • freezed_annotation

    Generates immutable data classes and unions; can be combined with custom Firestore wrappers.

Works with

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