FirebaseFirestore.instance
.collection('admin')
.doc('Geofence')
.get()
.then((value) {
geofenceModel = geofenceModel.fromMap//error here(value.data());
setState(() {
latitude = ("${geofenceModel.latitude}");
longitude = ("${geofenceModel.longitude}");
radius = ("${geofenceModel.radius}");
});
});
the error start from the "fromMap". Please help me to solve it
CodePudding user response:
Assuming you have the parameters you mentioned (lat, long, rad) as type String
for your GeoFenceModel
, you need to create the fromMap()
as follows:
class GeofenceModel {
String latitude;
String longitude;
String radius;
GeofenceModel({
required this.latitude,
required this.longitude,
required this.radius,
});
Map<String, dynamic> toMap() {
return <String, dynamic>{
'latitude': latitude,
'longitude': longitude,
'radius': radius,
};
}
factory GeofenceModel.fromMap(Map<String, dynamic> map) {
return GeofenceModel(
latitude: (map['latitude'] ?? '') as String,
longitude: (map['longitude'] ?? '') as String,
radius: (map['radius'] ?? '') as String,
);
}
}