diff --git a/lib/src/custom_map_marker_builder.dart b/lib/src/custom_map_marker_builder.dart index bff2e51..5ac9c59 100644 --- a/lib/src/custom_map_marker_builder.dart +++ b/lib/src/custom_map_marker_builder.dart @@ -70,7 +70,7 @@ class CustomMapMarkerBuilder extends StatelessWidget { /// A widget convert list of widgets into custom google maps marker icons. -class CustomGoogleMapMarkerBuilder extends StatelessWidget { +class CustomGoogleMapMarkerBuilder extends StatefulWidget { /// List of custom [MarkerData] each item is a google maps [Marker] and /// custom widget thar are going to be used as an icon for this marker. final List customMarkers; @@ -87,30 +87,48 @@ class CustomGoogleMapMarkerBuilder extends StatelessWidget { /// Widget builder that carries [imagesData] which is `null` when marker /// images are not ready yet or list of google maps [Marker] when custom /// markers are ready. - final Widget Function(BuildContext, Set? markers) builder; + final Widget Function(BuildContext, Set markers) builder; - const CustomGoogleMapMarkerBuilder( + CustomGoogleMapMarkerBuilder( {Key? key, required this.customMarkers, required this.builder, this.screenshotDelay = const Duration(milliseconds: 500)}) : super(key: key); + @override + State createState() => + _CustomGoogleMapMarkerBuilderState(); +} + +class _CustomGoogleMapMarkerBuilderState + extends State { + Set lastMarkers = {}; + @override Widget build(BuildContext context) { return CustomMapMarkerBuilder( - screenshotDelay: screenshotDelay, - markerWidgets: - customMarkers.map((customMarker) => customMarker.child).toList(), + screenshotDelay: widget.screenshotDelay, + markerWidgets: widget.customMarkers + .map((customMarker) => customMarker.child) + .toList(), builder: (BuildContext context, List? customMarkerImagesData) { - return builder( + if (customMarkerImagesData != null) { + lastMarkers = widget.customMarkers + .map((e) => e.marker.copyWith( + iconParam: BitmapDescriptor.fromBytes( + customMarkerImagesData[widget.customMarkers.indexOf(e)]))) + .toSet(); + } + return widget.builder( context, customMarkerImagesData == null - ? null - : customMarkers + ? lastMarkers + : widget.customMarkers .map((e) => e.marker.copyWith( iconParam: BitmapDescriptor.fromBytes( - customMarkerImagesData[customMarkers.indexOf(e)]))) + customMarkerImagesData![ + widget.customMarkers.indexOf(e)]))) .toSet()); }, );