Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Google Maps wont scroll sideways

Tags:

flutter

totally new to flutter / android dev.

I have a google map as a tab in a TabBar. A swipe left/right is being grabbed by the tab bar, rather than permitting the user to scroll the map. How can I let the map be scrolled. I've tried various permutations based on the following, but only up and down scrolling currently works.

GoogleMap(
        onMapCreated: _controller.complete,
        initialCameraPosition: _center,
        myLocationButtonEnabled: true,
        myLocationEnabled: true,
        scrollGesturesEnabled: true,
        gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>[
          Factory<OneSequenceGestureRecognizer>(
            // () => ScaleGestureRecognizer(),
            () => HorizontalDragGestureRecognizer(),
          ),
        ].toSet(),
        markers: mkMarkers(this.widget.viewModel.restos),
      )
like image 206
Simon H Avatar asked Apr 23 '26 02:04

Simon H


2 Answers

Disable the tabBar physics.

Unfortunately this will be for all tabs, but do you want to have scrolling doing different things on different tabs.

TabBarView(
        physics: NeverScrollableScrollPhysics(),
...       
      ),
like image 124
Glen Avatar answered Apr 25 '26 20:04

Glen


I have also a google map in a tab and I solved this by adding this gestureRecognizers on GoogleMap:

  gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{
              Factory<OneSequenceGestureRecognizer>(
                () => EagerGestureRecognizer(),
              ),
            },

Get the imports:

import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';

And that's it.

like image 37
Rafhaela Avatar answered Apr 25 '26 19:04

Rafhaela