Simon H
Simon H

Reputation: 21037

Flutter Google Maps wont scroll sideways

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),
      )

Upvotes: 2

Views: 1902

Answers (3)

Rafhaela
Rafhaela

Reputation: 103

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.

Upvotes: 4

A variant would be to disable that swipe function when you are in the tab referring to the map, then with the setState () you can reassign the variable so that the swipe behavior is normal.

Upvotes: 3

Glen
Glen

Reputation: 619

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(),
...       
      ),

Upvotes: 7

Related Questions