Issue
I’m actually on multiple dart projects which can share code. (based on this exemple)
This common code use a library named json_serializable
I’m using it to generate json serialization et deserialization methods for my user model.
I can use the commande pub run build_runner build
to start the build. This way I can generate user_model.g.dart
(which contains generated serialization and deserialization methods) from user_model.dart
Back to my project I’m adding my shared code as a dependency.
I’d like to use my user_model.dart
but there is an error saying that user_model.g.dart
doesn’t exist. Indeed I haven’t launch the build to generate this file.
I’m trying to find a way to launch this generation of code needed by my library but this must be done from my project.
I think I need to add a build file in my lib but I can’t find how to do it :/
Schema :
Project X –using–> Lib Sharing Code –using–> json_serialization
Solution
You need to commit generated code.
build_runner
can only generate code in the project it is run in, not in dependencies.
Answered By – Günter Zöchbauer
Answer Checked By – Pedro (FlutterFixes Volunteer)