I'm trying to set a custom icon for the markers of my map, in my Flutter app. Since BitmapDescriptor.fromAsset()
is deprecated, I'm sruggling to find how to use BitmapDescriptor.fromAssetImage()
.
I did not find any doc or Stackoverflow question about this.
This is the current way I'm creating it (without the custom image):
Marker(
markerId: MarkerId(pos.toString()),
position: pos,
infoWindow: InfoWindow(
title: store['store_name'],
snippet: '',
),
icon: BitmapDescriptor.defaultMarker));
Define a field in Class:
BitmapDescriptor myIcon;
Retrieve icon before the Map is ready.
@override
void initState() {
BitmapDescriptor.fromAssetImage(
ImageConfiguration(size: Size(48, 48)), 'assets/my_icon.png')
.then((onValue) {
myIcon = onValue;
});
}
set the Icon:
icon: myIcon;
Make sure you have set the icon in Flutter section of pubspec.yaml
assets:
- assets/my_icon.png
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With