firestore_builder

Last updated:

0 purchases

firestore_builder Image
firestore_builder Images
Add to Cart

Description:

firestore builder

Firestore Builder #


Installation #
Setup Firestore for your project #
Follow the official Firebase documentation to add Firestore to your project.
This will make you add the following dependencies :
flutter pub add firebase_core
flutter pub add cloud_firestore
copied to clipboard
Dependencies #
Add the firestore_builder package in dev_dependencies. You can do this by running this command:
flutter pub add dev:firestore_builder
copied to clipboard
Configuration #
Generation is based on a YAML configuration file (firestore_builder_config.yaml) that describes the structure of the database you want.
A. Use the devtools extension #
The simplest way to configure the generation is to use the devtools extension app :

Launch your app in debug mode
Open the devtool



Select the firestore_builder tab and enable the extension



Use the extension app to build the configuration file



You can save the configuration file directly from the extensions app, this will create the firestore_builder_config.yaml at the root of your project


B. Or manually create the configuration file #
If you master the configuration syntax, you can manually create the firestore_builder_config.yaml file at the root of your project. Here is a simple configuration file with only one collection (users)
firestore_builder:
output: lib/firestore
use_riverpod: true
collections:
- collection:
collection_name: users
model_name: user
fields:
- name: String
- age: int
copied to clipboard
Add external dependencies #
The generated code is based on external packages. Thanks @remi_rousselet for this.


The Freezed package to make models classes immutable and equatable.


(optionally) The Riverpod package. My personal favorite state management package


You need to add these dependencies :
Freezed #
flutter pub add freezed_annotation
flutter pub add dev:build_runner
flutter pub add dev:freezed
flutter pub add json_annotation
flutter pub add dev:json_serializable
copied to clipboard
Riverpod (Optional) #
flutter pub add flutter_riverpod
copied to clipboard
Generate the Freezed classes #
Do not forget to run the build_runner command line each time you generate new code :
dart run build_runner build --delete-conflicting-outputs
copied to clipboard
Generation result #
With a simple configuration file, here is the result of the generation:
lib
-- firestore
-- models
-- updated_value.dart
-- user.dart
-- user.freezed.dart
-- user.g.dart
-- services
-- firestore_query_service.dart
-- firestore_reference_service.dart
-- firestore_stream_service.dart
-- states
-- user_states.dart
copied to clipboard

updated_value.dart is a helper class that allows to update some properties of a document
user.dart is the model class of the user collection.
firestore_query_service.dart is the service to make API call (get, add, delete, update, …)
firestore_reference_service.dart is the service to easily access to the Firestore references (documents or collections)
firestore_stream_service.dart is the service to consume Firestore data through streams
user_states.dart is where the Riverpod providers are defined

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.