The Cloud Firestore ODM is currently in alpha. Expect breaking changes, API changes and more. The documentation is still a work in progress. See the discussion for more details.
The power of the ODM comes from code generation. The models created need to be run through code generation to allow for the full type safety which the ODM offers.
When defining models we include a part
declaration -
this declaration references a file which have not yet generated.
Within the root of your project, run the following command to run code generation against the defined models:
dart run build_runner build --delete-conflicting-outputs
During development, you can watch for changes and automatically update the generated code:
dart run build_runner watch --delete-conflicting-outputs
This will generate files with the postfix of .g.dart
, corresponding to the
file name of your model. For example:
- A model is defined within a file named
product.dart
. - Code generation will create a file in the same directory named
product.g.dart
. - Within the
product.dart
file, apply the part declaration (part 'product.g.dart'
).
With our code generated, we can now start to use the references.