gitdartfluttercode-generation

Should I commit generated code in Flutter/Dart to VCS


I'm using the Retrofit (https://pub.dev/packages/retrofit) and Json Serializable (https://pub.dev/packages/json_serializable) libraries for Flutter which both create generated code files that end up amongst the rest of the source code. Should the generated x.g.dart files be committed in VCS?

In normal Android/Java development the generated files go into special gen/out/build folders that you don't commit and the IDE is usually pretty good at hiding these files. But since Flutter generates them in the source I'm not sure what to do with them.


Solution

  • It is best not to commit the generated files generally. As recommended by the build_runner itself. Here is the link to the source control section of the package.

    Also, it mentions two things to consider.

    1. A specific builder's recommendation should supersede these recommendations if different.
    2. In some case generated files can cause 'already exists' warnings. I have seen this myself multiple times.