Skip to content

Instantly share code, notes, and snippets.

@liubrandon
Last active January 15, 2021 02:56
Show Gist options
  • Save liubrandon/6ddb2a063d1856bd6334b6a12ca088ee to your computer and use it in GitHub Desktop.
Save liubrandon/6ddb2a063d1856bd6334b6a12ca088ee to your computer and use it in GitHub Desktop.
Google Maps Gesture Issue
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:pointer_interceptor/pointer_interceptor.dart';
Future<void> main() async {
runApp(GoogleMapsGestureIssue());
}
class GoogleMapsGestureIssue extends StatefulWidget {
@override
_GoogleMapsGestureIssueState createState() => _GoogleMapsGestureIssueState();
}
class _GoogleMapsGestureIssueState extends State<GoogleMapsGestureIssue> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Stack(
children: [
_buildGoogleMap(),
Align(
alignment: Alignment.topCenter,
child: Padding(
padding: EdgeInsets.only(top: 72),
child: Container(
height: 40,
child: PointerInterceptor( // This prevents the Google Map underneath from recieving gestures directly underneath
child: ListView(
scrollDirection: Axis.horizontal,
children: _listOfContainers()
),
),
)
)
)
]
),
),
);
}
Widget _buildGoogleMap() {
// Neither AbsorbPointer nor IgnorePointer cause GoogleMap to ignore gestures
return AbsorbPointer(
absorbing: true,
child: IgnorePointer(
ignoring: true,
child: GoogleMap(
onTap: (_) {},
zoomControlsEnabled: false,
mapType: MapType.normal,
initialCameraPosition: CameraPosition(
target: LatLng(0, 0),
zoom: 0,
),
onMapCreated: (controller) {},
gestureRecognizers: null,
// Setting gestureRecognizers to null or empty set should allow
// the ListView scrolling to win in the gesture arena but nothing occurs
),
),
);
}
List<Widget> _listOfContainers() {
return [
Container(
width: 160.0,
color: Colors.red,
),
Container(
width: 160.0,
color: Colors.blue,
),
Container(
width: 160.0,
color: Colors.green,
),
Container(
width: 160.0,
color: Colors.yellow,
),
Container(
width: 160.0,
color: Colors.orange,
),
Container(
width: 160.0,
color: Colors.red,
),
Container(
width: 160.0,
color: Colors.blue,
),
Container(
width: 160.0,
color: Colors.green,
),
Container(
width: 160.0,
color: Colors.yellow,
),
Container(
width: 160.0,
color: Colors.orange,
),
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment