I got two different screens inside Flutter app that use Google Map (provided by this library).
Widget structure for first one is
Scaffold -> ListView -> Visibility -> Center -> SizedBox -> GoogleMap
and for second screen it is
Scaffold -> Container -> Column -> SizedBox -> GoogleMap
On both screens I got same map settings but for some reason on the first screen map is not responding to any touch events.
I was with the same problem and I found the following solution after a long time of searching, just so it will work:
GoogleMap(
gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>[
new Factory<OneSequenceGestureRecognizer>(() => new EagerGestureRecognizer(),),
].toSet(),)
The reason is that the EagerGestureRecognizer
is a gesture recognizer that eagerly claims victory in all gesture arenas.
Reference:
Manage gestures priority between two widgets
propriedade gestureRecognizers
You need to tell the GoogleMap
widget which gestures you want it to respond to by setting the gestureRecognizers
property, something like this:
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
...
GoogleMap(
initialCameraPosition: CameraPosition(
target: LatLng(0, 0),
),
gestureRecognizers: Set()
..add(Factory<PanGestureRecognizer>(() => PanGestureRecognizer()))
);
This is not specific to the GoogleMap
widget, you would need to do this with any widget that uses AndroidView
/UIKitView
under the covers to handle gestures when it's placed inside a scrollable view.
I think it depends of what kind of gestures your parent widget support.
This way works for me. My map is in TabBarView > ListView > GoogleMap
GoogleMap(
gestureRecognizers: Set()
..add(Factory<PanGestureRecognizer>(() => PanGestureRecognizer()))
..add(Factory<ScaleGestureRecognizer>(() => ScaleGestureRecognizer()))
..add(Factory<TapGestureRecognizer>(() => TapGestureRecognizer()))
..add(Factory<VerticalDragGestureRecognizer>(
() => VerticalDragGestureRecognizer())),
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With