Skip to content

[web] Pinch-zooming gesture using macbook touchpad is not recognized on web. #112103

@SaadArdati

Description

@SaadArdati

Steps to Reproduce

  1. Run the sample app in a MacOS window.
  2. Pinch to zoom in and out, you will see the colored box will grow and shrink.
  3. You can click on the scale text in the center to reset the scale.
  4. Run the sample app in a browser and try again.

Expected results: Pinch-zooming to work on web.

Actual results: Pinch-zooming does not work on web. Instead, panning is triggered.

Code sample

https://dartpad.dev/?id=81f8b56fccf7ab611a66c0b4a9ca385e

https://gist.github.com/SwissCheese5/81f8b56fccf7ab611a66c0b4a9ca385e

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'MyApp Demo',
      home: Scaffold(
        body: Center(
          child: SingleChildScrollView(
            child: MainWidget(),
          ),
        ),
      ),
      debugShowCheckedModeBanner: false,
    );
  }
}

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

  @override
  State<MainWidget> createState() => _MainWidgetState();
}

class _MainWidgetState extends State<MainWidget> {
  double scale = 1.0;

  double scaleStart = 1.0;

  @override
  Widget build(BuildContext context) {
    return Listener(
      onPointerPanZoomStart: (event) {
        scaleStart = scale;
      },
      onPointerPanZoomUpdate: (event) {
        setState(() {
          scale = scaleStart * event.scale;
        });
      },
      onPointerPanZoomEnd: (event) {
        scaleStart = scale;
      },
      child: Container(
        // This will ensure that the entire window space is covered by the
        // listener.
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        // The color ensure that the hit test succeeds.
        decoration: BoxDecoration(
          color: Colors.green.withOpacity(0.1),
          border: Border.all(color: Colors.black, width: 3),
        ),
        child: Stack(
          alignment: Alignment.center,
          children: [
            Transform.scale(
              scale: scale,
              child: Center(
                child: Container(
                  width: 300,
                  height: 300,
                  decoration: BoxDecoration(
                    border: Border.all(color: Colors.black, width: 3),
                    gradient: const LinearGradient(
                      begin: Alignment.topLeft,
                      end: Alignment.bottomRight,
                      colors: [
                        Colors.red,
                        Colors.green,
                        Colors.blue,
                      ],
                    ),
                  ),
                ),
              ),
            ),
            Material(
              color: Colors.transparent,
              child: InkWell(
                onTap: () {
                  setState(() {
                    scale = 1.0;
                  });
                },
                child: Container(
                    decoration: BoxDecoration(
                      border: Border.all(color: Colors.black, width: 1),
                      color: Colors.white.withOpacity(0.5),
                      borderRadius: BorderRadius.circular(4),
                    ),
                    padding: const EdgeInsets.all(4),
                    child: Text('Scale: ${scale.toStringAsPrecision(3)}')),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
Logs

Github has a character limit. Log exceeded it. Here's a gist of the log output:

https://gist.github.com/SwissCheese5/e09e4825a186403747a606f5a9a02751


Analyzing flutter_pinch_zoom_bug...
No issues found! (ran in 1.1s)


[✓] Flutter (Channel stable, 3.3.1, on macOS 12.6 21G115 darwin-arm, locale en-LB)
• Flutter version 3.3.1 on channel stable at /Users/saadardati/Desktop/development/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 4f9d92fbbd (2 weeks ago), 2022-09-06 17:54:53 -0700
• Engine revision 3efdf03e73
• Dart version 2.18.0
• DevTools version 2.15.0

[!] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
• Android SDK at /Users/saadardati/Library/Android/sdk
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

[✓] Xcode - develop for iOS and macOS (Xcode 14.0)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 14A309
• CocoaPods version 1.11.3

[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)

[✓] IntelliJ IDEA Ultimate Edition (version 2022.2.2)
• IntelliJ at /Applications/IntelliJ IDEA.app
• Flutter plugin version 70.0.5
• Dart plugin version 222.4167.21

[✓] VS Code (version 1.71.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.48.0

[✓] Connected device (2 available)
• macOS (desktop) • macos  • darwin-arm64   • macOS 12.6 21G115 darwin-arm
• Chrome (web)    • chrome • web-javascript • Google Chrome 105.0.5195.125

[✓] HTTP Host Availability
• All required HTTP hosts are available

! Doctor found issues in 1 category.

MacOS window:

Screen.Recording.2022-09-21.at.4.02.24.PM.mov

Chrome window:
You can't see it, but I'm aggressively pinch-zooming in this video...

Screen.Recording.2022-09-21.at.4.01.18.PM.mov

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityengineflutter/engine related. See also e: labels.found in release: 3.3Found to occur in 3.3found in release: 3.4Found to occur in 3.4frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-webWeb applications specificallyr: solvedIssue is closed as solvedteam-webOwned by Web platform teamtriaged-webTriaged by Web platform team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions