GithubHelp home page GithubHelp logo

zaraclaj / firestore_builder Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 10.8 MB

License: MIT License

Dart 14.03% JavaScript 84.14% MDX 0.09% CSS 0.05% Kotlin 0.01% Shell 0.01% Ruby 0.09% Swift 0.06% Objective-C 0.01% CMake 0.59% C++ 0.73% C 0.04% HTML 0.17%

firestore_builder's Introduction

Firestore Builder

Pub

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

Dependencies

Add the firestore_builder package in dev_dependencies. You can do this by running this command:

flutter pub add dev:firestore_builder

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

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

Riverpod (Optional)

flutter pub add flutter_riverpod

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

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
  • 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

firestore_builder's People

Contributors

jordanalcaraz avatar zaraclaj avatar

Stargazers

Ilyas LEFEBVRE avatar Aloïs Deniel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.