According to the json_serializable package installing instructions, you should add the following dependency:
dependencies:
json_serializable: ^2.0.3
This is my code:
import 'package:json_annotation/json_annotation.dart';
part 'person.g.dart';
@JsonSerializable(nullable: false)
class Person {
final String firstName;
final String lastName;
final DateTime dateOfBirth;
Person({this.firstName, this.lastName, this.dateOfBirth});
factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);
Map<String, dynamic> toJson() => _$PersonToJson(this);
}
Now running this in Flutter:
flutter packages pub run build_runner build
Or this for a Dart project:
pub run build_runner build
I get the following error:
Could not find package "build_runner". Did you forget to add a dependency?
What's wrong?