I have added a comment in front of some lines that says 'not needed'. I added this to mark the lines that I think is not related to the question. (The reason I did not remove those lines is, in case that those lines are related to the question, readers can read them too.)
class _SafeSheltersPageState extends State<SafeSheltersPage> {
Future sheltersFuture; // not needed
BitmapDescriptor mapMarker1;
BitmapDescriptor mapMarker2;
void setCustomMarker(mapMarker, icon) async {
mapMarker = await BitmapDescriptor.fromAssetImage(
ImageConfiguration(),
icon,
);
}
sheltersFutureBuilder() async {
CurrentLocation currentLocation = await CurrentLocationUtil().getLocation(); // not needed
Map<String, Object> data = { // not needed
'location': { // not needed
'latitude': currentLocation.latitude, // not needed
'longitude': currentLocation.longitude, // not needed
} // not needed
}; // not needed
return CallApi().postData(data, 'public/api/getShelterLocations'); // not needed
} // not needed
@override
void initState() {
super.initState();
setCustomMarker(mapMarker1, 'images/map/user_location.png');
setCustomMarker(mapMarker2, 'images/map/safe_shelter.png');
sheltersFuture = sheltersFutureBuilder(); // not needed
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Safe Shelters'),
centerTitle: true,
backgroundColor: Colors.red.shade300,
),
body: SafeArea(
child: FutureBuilder(
future: sheltersFuture,
builder: (context, snapshot) {
if (snapshot.hasData) {
String responseBody = snapshot.data.body; // not needed
var data = jsonDecode(responseBody); // not needed
double userCurrentLatitude = data['current_loc']['latitude']; // not needed
double userCurrentLongitude = data['current_loc']['longitude']; // not needed
double nearestShelterLat = double.parse(data['shelters']['nearest_shelter'][0]['latitude']); // not needed
double nearestShelterLon = double.parse(data['shelters']['nearest_shelter'][0]['longitude']); // not needed
final Set<Marker> markers = {
Marker(
markerId: MarkerId('user-loc'),
position: LatLng(userCurrentLatitude, userCurrentLongitude),
icon: mapMarker1,
infoWindow: InfoWindow(
title: 'You',
snippet: 'You are currently here!',
),
),
Marker(
markerId: MarkerId('nearest-shelter'),
position: LatLng(nearestShelterLat, nearestShelterLon),
icon: mapMarker2,
infoWindow: InfoWindow(
title: 'Nearest Safe Shelter',
snippet:
'This is the nearest safe shelter from your location',
),
),
};
return GoogleMap(
markers: markers,
initialCameraPosition: CameraPosition(
target: LatLng(userCurrentLatitude, userCurrentLongitude),
zoom: 15,
),
);
}
},
),
),
);
}
}
In the above code, no matter how hard I try using the function setCustomMarker
, that I have defined, the icon I get on my mobile screen are default location icons.
Assets are correctly added to the pubspec.yaml
file.
I would be really helpful if someone can point out to me what I am doing wrong and how to fix this. Thanks.