json_serializable plugin of Dart, does a great job of automatically generating some error prone and cumbersome parts of code, in exchange for some boilerplate: two methods, one annotation, and one reference to the generated file.
import 'package:json_annotation/json_annotation.dart';
part 'location.g.dart';
@JsonSerializable()
class Location {
final double lat;
final double lng;
Location(this.lat, this.lng);
factory Location.fromJson(Map<String, dynamic> json) =>
_$LocationFromJson(json);
Map<String, dynamic> toJson() => _$LocationToJson(this);
}
Obviously this better be done also by the machine, like the constructor for this class: I just write the final field, then press alt+enter and Android Studio places the constructor for me.
Does someone know how to make Android Studio do that for json_serializable?