rorystephenson / flutter_map_marker_popup

Popups for flutter_map markers
BSD 3-Clause "New" or "Revised" License
103 stars 84 forks source link

How to add button inside popup #26

Closed mohammedX6 closed 3 years ago

mohammedX6 commented 3 years ago

Hi, I want to add a button inside the popup, it showed without any problem but I click on the button nothing happens after some research I find that when I click on the button the map on tap event fired its like I am tapping on the map layer itself, not on the popup button.

rorystephenson commented 3 years ago

Hi @killerm250m, can you provide a minimal code example that demonstrates the issue?

I just tried and the following works:

class ExamplePopupWithButton extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Card(
      child: TextButton(
        onPressed: () {
          debugPrint('Button pressed!');
        },
        child: Text('A button'),
      ),
    );
  }
}

You can use this for the popupBuilder like so:

PopupMarkerLayerWidget(
  options: PopupMarkerLayerOptions(
    popupBuilder: (BuildContext context, Marker marker) =>
                ExamplePopupWithButton(),
    # ...
  ),
  # ...
)
rorystephenson commented 3 years ago

@killerm250m I am closing as adding a button seems to work but if I've misunderstood the request please comment and I will have another look :).