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.
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.
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?
flutter run.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With