I migrated to null safety and i cant run "flutter pub run build_runner build" without an error being thrown
Please make sure all of your packages are updated to their respective null-safety version. For build runner use ^1.12.2
and then run below commands in your terminal while sitting in the present working directory.
flutter cleanflutter pub cache repairflutter pub run build_runner cleanflutter pub get
After then run the build runner command.
This worked for me and I've successfully generated the files using the build runner.
Delete the .pub-cache
folder inside your flutter folder and then run pub upgrade
, after that you should be able to run:
flutter packages pub run build_runner build --delete-conflicting-outputs
For those who are you using full sound null-safety i.e. who are not using @dart=2.9
or other means to ignore null-safety.
In your pubspec.yaml
file, the lower SDK version should be >=2.12
.
environment: sdk: '>=2.12.0 <3.0.0'
Use the following versions (all are null-safe)
json_annotation: ^4.0.1json_serializable: ^4.1.2build_runner: ^2.0.3