Why doesn't build_runner generate files when serializing JSON in dart/flutter
I had a similar issue, but I am using Android Studio IDE and I have done the following step:
File => Invalidate caches / Restart
Run following command:
flutter cleanflutter pub getflutter packages pub run build_runner build --delete-conflicting-outputs
If you read the error message carefully, you'll see that it's asking you to try adding --delete-conflicting-outputs
at the end of your command. So you should try flutter packages pub run build_runner build --delete-conflicting-outputs
.
In my case adding part 'file_name.g.dart';
to the top of the file helped.
file_name.dart:
import 'package:json_annotation/json_annotation.dart';part 'file_name.g.dart';@JsonSerializable()class YourClass { factory YourClass.fromJson(Map<String, dynamic> json) => _$YourClassFromJson(json); Map<String, dynamic> toJson() => _$YourClassToJson(this); // ... your class code}