I have a map with map markers that is created from custom code and I'm trying to make it show a bottom sheet when the user taps a map marker. Similar to how Zillow works - the user taps the marker, it pulls up a bottom sheet and shows details of that marker within the bottom sheet.
I have the bottom sheet created as a component already but I need to figure out how to call that component from within the custom code.
There are tons of videos and write-ups on how to create a bottom sheet from scratch within the custom code and/or how to create one in the UI but I can't seem to find anything about integrating an existing bottom sheet (created in the UI) into a custom widget. Surely there is some kind of import statement/navigation action that can be done, rather than copy/pasting the code from the bottom sheet into the custom widget.
I'd like to do it this way so that if I need to make changes to the bottom sheet, I don't have to mess with the code, I can just do it from the UI (I'm not a developer but I understand the theories and concepts).
The code below is where we currently sit (which doesn't work, but some of you probably already know that ๐ )
void _updateMarkersFromQuery(Iterable<QueryDocumentSnapshot> docs) {
final newMarkers = <google_maps_flutter.Marker>{};
for (var doc in docs) {
try {
final double latitude = doc['latitude'];
final double longitude = doc['longitude'];
final String address = doc['address'] ?? 'Unknown Address';
final marker = google_maps_flutter.Marker(
markerId: google_maps_flutter.MarkerId(doc.id),
position: google_maps_flutter.LatLng(latitude, longitude),
infoWindow: google_maps_flutter.InfoWindow(title: address),
onTap: () {
showModalBottomSheet(
context: context,
builder: (context) {
return GestureDetector(
onTap: () => Navigator.pop(context),
child: SizedBox(
height: MediaQuery.of(context).size.height * 0.5,
child:
listingDetails(), // Use your existing bottom sheet component
docId: doc.id, // Pass parameters if needed
latitude: latitude.toString(),
longitude: longitude.toString(),
address: address,
),
);
},
);
},
);