How to make flutter Google Maps scrollable only with two fingers in SingleChildScrollView

Viewed 59

I have gestureRecognizers parameter set like this:

child: GoogleMap(
            initialCameraPosition: widget.cameraPosition!,
            gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>[
              new Factory<OneSequenceGestureRecognizer>(
                    () => new EagerGestureRecognizer(),
              ),
            ].toSet(),

but it's allowing to scroll maps only with one finger, but I want it possible only with two? I heard it's possible but how?

1 Answers

Look here: https://gist.github.com/awaik/7d5b6d6ec644ae844a3740dddc990ed4

it's a sample app with implementation of two finger swipe:

class SwipeDemo extends StatefulWidget {
  const SwipeDemo({Key? key}) : super(key: key);

  @override
  SwipeDemoState createState() => SwipeDemoState();
}

class SwipeDemoState extends State<SwipeDemo> {
  Offset offset = Offset.zero;

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: TwoFingerPointerWidget(
        onUpdate: (details) {
          setState(() {
            offset += details.delta;
          });
        },
        child: Container(
          alignment: Alignment.center,
          color: Colors.white,
          child: Transform.translate(
            offset: offset,
            child: Container(
              width: 100,
              height: 100,
              color: Colors.red,
            ),
          ),
        ),
      ),
    );
  }
}
Related