Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 841
James Pace Avatar asked Mar 29 '26 22:03

James Pace


1 Answers

TLDR: The flutter tooling is not advanced enough for this. Working around this today would add more complexity to your project. Generally committing source code is a debatable opinion, see Should I store generated code in source control, but for Flutter specifically, it is very much in favour of keeping the generated source code files in git.

  • Current practices: Google developers working on a flutter plugin package (video_player) have committed generated files to their repository.
  • Tool limitation: flutter run does not seem to support running codegen on compilation / build, so you're asking users to manually run code generation when copying the repo, writing a script and asking users to do this (and making IDE support worse/tedious), or setting up a client side or server side Git hook. These are all complexities to solve what problem actually? The fact that in other ecosystems you don't commit generated files?
    • causes extra configuration: You may add more configuration work (and skill required) to set up an IDE correctly. Of course, a good developer can share their configuration by putting Android Studio configuration in the git repo, but Flutter developers may expect to be able to run flutter run.
  • Convention over configuration: Would a developer who starts in your project need to manually run code generation or use a specific IDE that you use then? Or learn how to configure their IDE of choice to launch the app? In that case, we are adding overhead to the developer who works on this project. Aim for simplicity, not just for your sake, but everyone else's sake.
  • Lowest common denominator output: Flutter is different to Android / Gradle (or other ecosystems), and we should not try to make things consistent (standardise) at the cost of getting the lowest common denominator output. Flutter does not have a flutter sync command that is automatically run by the IDE when it launches, so there is no way to run this code generation automatically.

Existing discussion: There is a discussion on Flutter about improving the code generation experience (https://github.com/flutter/flutter/issues/63323). Committing generated files is such a small aspect of a feature.

like image 82
Ben Butterworth Avatar answered Apr 02 '26 06:04

Ben Butterworth