I get this issue only in Flutter Web, when I add some widgets over the Google Map widget(overlay), the click and cursor functionality doesn't work properly and on every widget I click it triggers the GoogleMap widget as well.
This is an example:
Image Screenshot, I used the Stack
widget and put GoogleMap
and the other widgets in it.
Here's the code: When you click on the button you will see onTap function of the GoogleMap will triggers as well
main(){
runApp(MaterialApp(
home: Home(),
));
}
class Home extends StatefulWidget {
const Home({Key? key}) : super(key: key);
@override
State<Home> createState() => _HomeState();
}
class _HomeState extends State<Home> {
late CameraPosition _cameraPosition;
@override
void initState() {
super.initState();
_cameraPosition = const CameraPosition(
target: LatLng(52.046846, 4.299154),
zoom: 20,
);
}
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Scaffold(
body: SizedBox(
height: height,
width: width,
child: Stack(
children: [
GoogleMap(
initialCameraPosition: _cameraPosition,
onTap: (latlng){
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('on Map Tap')));
},
),
Align(
alignment: Alignment.center,
child: ElevatedButton(
onPressed: (){
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Yay! A SnackBar!')));
},
child: const Text("Click me"),
),
),
],
),
),
);
}
}
Is there any way to fix these issues? Thanks in advance.