flutterfire_gen 0.4.3 copy "flutterfire_gen: ^0.4.3" to clipboard
flutterfire_gen: ^0.4.3 copied to clipboard

flutterfire_gen is a package for automatic code generation for Cloud Firestore. It supports efficient CRUD operations with type-safe interfaces and methods.

example/lib/main.dart

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';

import 'todo.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

  final query = TodoQuery();

  final todos = await query.fetchDocuments();
  for (final todo in todos) {
    print(todo.todoId);
  }

  final notCompletedTodos = await query.fetchDocuments(
    queryBuilder: (query) => query.where('isCompleted', isNotEqualTo: true),
  );
  for (final todo in notCompletedTodos) {
    print(todo.todoId);
  }

  query.subscribeDocuments();

  query.subscribeDocuments(
    queryBuilder: (query) => query.where('isCompleted', isNotEqualTo: true),
  );

  final todosAsCollectionGroup =
      await query.fetchDocuments(asCollectionGroup: true);
  for (final todo in todosAsCollectionGroup) {
    print(todo.todoId);
  }

  query.subscribeDocuments(asCollectionGroup: true);

  final todo = await query.fetchDocument(todoId: 'todoId');
  print(todo?.todoId);

  final todosCount = await query.count();
  print(todosCount);

  final addedDocumentReference =
      await query.add(createTodo: const CreateTodo(title: 'A new Todo'));
  print(addedDocumentReference.id);

  await query.set(
    todoId: 'anotherTodoId',
    createTodo: const CreateTodo(title: 'Another Todo'),
  );

  await query.update(
    todoId: 'todoId',
    updateTodo: const UpdateTodo(isCompleted: true),
  );

  await query.delete(todoId: 'todoId');

  await query.batchWrite([
    const BatchCreateTodo(
      todoId: 'newTodoId',
      createTodo: CreateTodo(title: 'A new Todo'),
    ),
    const BatchUpdateTodo(
      todoId: 'todoId',
      updateTodo: UpdateTodo(isCompleted: true),
    ),
    const BatchDeleteTodo(todoId: 'anotherTodoId'),
  ]);
}
22
likes
160
pub points
65%
popularity

Publisher

verified publisherkosukesaigusa.com

flutterfire_gen is a package for automatic code generation for Cloud Firestore. It supports efficient CRUD operations with type-safe interfaces and methods.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

analyzer, build, cloud_firestore, flutter, flutterfire_gen_annotation, flutterfire_gen_utils, json_annotation, meta, path, source_gen

More

Packages that depend on flutterfire_gen