Flutter: Could not generate user.g.dart with atribute geopoint


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';

class UserData {
  final String uid;
  late final String name;
  final String surname;
  final List<Location> location;

      {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);

class Location {
  String locationName;
  GeoPoint point;

  Location({required this.locationName, required this.point});
  factory Location.fromJson(Map<String, dynamic> json) =>

  Map<String, dynamic> toJson() => _$LocationToJson(this);




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)

Leave a Reply

Your email address will not be published. Required fields are marked *