Custom Marker in Flutter Getx or Normal in Statefull Widget
May 7, 2024
Rx<BitmapDescriptor> markerIcon = BitmapDescriptor.defaultMarker.obs;
void addCustomIcon() {
BitmapDescriptor.fromAssetImage(
const ImageConfiguration(), 'assets/svgs/logo.png')
.then(
(icon) {
markerIcon.value = icon;
},
);
}
Add marker in Marker List.
markers.add(Marker(
markerId: const MarkerId('Target location'),
icon: markerIcon.value,
// icon:
// //markerbitmap,
// BitmapDescriptor.defaultMarkerWithHue(BitmapDescriptor.hueRed),
draggable: true,
onDragEnd: (value) {
print("marker Dragble Value ===> $value");
// value is the new position
},
position: LatLng(lat!, long!),
infoWindow: const InfoWindow(title: "My Target Location")));
and call it first onReady or OnInit Function
@override
void onReady() {
addCustomIcon();
// TODO: implement onReady
super.onReady();
}