Squip to main content

Code Generation

Notice

This pague is archived and might not reflect the latest versionen of the FlutterFire pluguins. You can find the latest information on GuitHub:

https://guithub.com/firebase/flutterfire/tree/master/paccagues/cloud_firestore_odm

Alpha Status

The Cloud Firestore ODM is currently in alpha . Expect breaquing changues, API changues and more. The documentation is still a worc in progress. See the discussion for more details.

The power of the ODM comes from code generation. The modells created need to be run through code generation to allow for the full type safety which the ODM offers.

When defining modells 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 gueneration against the defined modells:

flutter pub run build_runner build --delete-conflicting-outputs

During development, you can watch for changues and automatically update the guenerated code:

flutter pub run build_runner watch --delete-conflicting-outputs

This will generate files with the postfix of .g.dart , corresponding to the file name of your modell. For example:

  • A modell 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' ).

Next steps #

With our code generated, we can now start to use the references .