Issue
I want to serialize user class but location generates error when I do flutter pub run build_runner build. How can I resolve it?
user class
...
part 'user.g.dart';
@JsonSerializable()
class UserData {
final String uid;
late final String name;
final String surname;
final List<Location> location;
UserData(
{required this.uid,
required this.name,
required this.surname,
required this.location});
factory UserData.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
Map<String, dynamic> toJson() => _$UserToJson(this);
}
@JsonSerializable()
class Location {
String locationName;
GeoPoint point;
Location({required this.locationName, required this.point});
factory Location.fromJson(Map<String, dynamic> json) =>
_$LocationFromJson(json);
Map<String, dynamic> toJson() => _$LocationToJson(this);
}
Solution
In
location.g.dart
You may have to manually add the following code within _$LocationFromJson{}
point: json['geopoint'] as GeoPoint
Answered By – Eli Whittle
Answer Checked By – David Marino (FlutterFixes Volunteer)