Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions lib/src/custom_map_marker_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<MarkerData> customMarkers;
Expand All @@ -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<Marker>? markers) builder;
final Widget Function(BuildContext, Set<Marker> markers) builder;

const CustomGoogleMapMarkerBuilder(
CustomGoogleMapMarkerBuilder(
{Key? key,
required this.customMarkers,
required this.builder,
this.screenshotDelay = const Duration(milliseconds: 500)})
: super(key: key);

@override
State<CustomGoogleMapMarkerBuilder> createState() =>
_CustomGoogleMapMarkerBuilderState();
}

class _CustomGoogleMapMarkerBuilderState
extends State<CustomGoogleMapMarkerBuilder> {
Set<Marker> 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<Uint8List>? 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());
},
);
Expand Down