Skip to content

PanGestureRecognizer with non-primary button gets cancelled when dragging out of the window #166309

Description

@sunarya-thito

Steps to reproduce

  1. Run as Windows Application
  2. Press middle mouse button on the blue container
  3. Hold and drag it out of the application window

Expected results

The gesture recognizer still receives updates when dragging out of the window until the mouse button is released

Actual results

The gesture recognizer invokes onEnd immediately after dragging it out of the window
This does not happen with primary mouse button, when using primary mouse button, the gesture recognizer still receives pointer update even when the cursor is no longer inside the application window.

Code sample

Code sample
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

void main(List<String> args) {
  runApp(MaterialApp(home: Test()));
}

class Test extends StatelessWidget {
  const Test({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: RawGestureDetector(
        gestures: {
          PanGestureRecognizer:
              GestureRecognizerFactoryWithHandlers<PanGestureRecognizer>(
                () => PanGestureRecognizer(
                  debugOwner: this,
                  allowedButtonsFilter: (buttons) {
                    //return buttons & kTertiaryButton != 0;
                    return true;
                  },
                ),
                (PanGestureRecognizer instance) {
                  instance.onStart = (details) {
                    print('onStart: ${details.globalPosition}');
                  };
                  instance.onUpdate = (details) {
                    print('onUpdate: ${details.globalPosition}');
                  };
                  instance.onEnd = (details) {
                    print('onEnd: ${details.globalPosition}');
                  };
                  instance.onCancel = () {
                    print('onCancel');
                  };
                },
              ),
        },
        behavior: HitTestBehavior.deferToChild,
        child: Center(
          child: Container(width: 100, height: 100, color: Colors.blue),
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[√] Flutter (Channel stable, 3.29.2, on Microsoft Windows [Version 10.0.22631.5039], locale en-ID) [382ms]
    • Flutter version 3.29.2 on channel stable at D:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c236373904 (3 weeks ago), 2025-03-13 16:17:06 -0400
    • Engine revision 18b71d647a
    • Dart version 3.7.2
    • DevTools version 2.42.3

[√] Windows Version (11 Home Single Language 64-bit, 23H2, 2009) [1,982ms]

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [352ms]
    • Android SDK at D:/Android/Sdk
    X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/to/windows-android-setup for more details.

[√] Chrome - develop for the web [224ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Build Tools 2019 16.11.31) [223ms]
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
    • Visual Studio Build Tools 2019 version 16.11.34114.132
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2024.1) [18ms]
    • Android Studio at D:\Program Files\Android\Android Studio2
    • 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 17.0.11+0--11852314)

[√] IntelliJ IDEA Ultimate Edition (version 2024.2) [17ms]
    • IntelliJ at D:\Program Files\JetBrains\IntelliJ IDEA 2024.2
    • 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

[√] Connected device (3 available) [161ms]
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22631.5039]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 134.0.6998.178
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 134.0.3124.93

[√] Network resources [379ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.

Activity

  1. danagbemava-nc commented on Apr 1, 2025

    @danagbemava-nc
    Member

    Reproducible using the code sample and steps provided above. This worked as expected on macOS. It most likely might be due to how lifecycle events are handled on windows. Labeling for further investigation

    flutter doctor -v
    [√] Flutter (Channel stable, 3.29.2, on Microsoft Windows [Version 10.0.26100.3194], locale en-US) [700ms]
        • Flutter version 3.29.2 on channel stable at C:\Users\Deana\fvm\versions\stable
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision c236373904 (3 weeks ago), 2025-03-13 16:17:06 -0400
        • Engine revision 18b71d647a
        • Dart version 3.7.2
        • DevTools version 2.42.3
    
    [√] Windows Version (11 Home 64-bit, 24H2, 2009) [4.7s]
    
    [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [4.2s]
        • Android SDK at C:\Users\Deana\AppData\Local\Android\sdk
        • Platform android-35, build-tools 34.0.0
        • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
          This is the JDK bundled with the latest Android Studio installation on this machine.
          To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
        • All Android licenses accepted.
    
    [√] Chrome - develop for the web [166ms]
        • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
    
    [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.2) [164ms]
        • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
        • Visual Studio Community 2022 version 17.8.34322.80
        • Windows 10 SDK version 10.0.22621.0
    
    [√] Android Studio (version 2023.1) [36ms]
        • Android Studio at C:\Program Files\Android\Android Studio
        • 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 17.0.7+0-b2043.56-10550314)
    
    [√] VS Code (version 1.98.0) [31ms]
        • VS Code at C:\Users\Deana\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.106.0
    
    [√] Connected device (3 available) [402ms]
        • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26100.3194]
        • Chrome (web)      • chrome  • web-javascript • Google Chrome 133.0.6943.142
        • Edge (web)        • edge    • web-javascript • Microsoft Edge 134.0.3124.93
    
    [√] Network resources [827ms]
        • All expected network resources are available.
    
    • No issues found!
    
    [!] Flutter (Channel master, 3.31.0-1.0.pre.356, on Microsoft Windows [Version 10.0.26100.3194], locale en-US) [5.2s]
        • Flutter version 3.31.0-1.0.pre.356 on channel master at C:\Users\Deana\fvm\versions\master  
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision a48a1f07b8 (3 hours ago), 2025-03-31 22:15:25 -0700
        • Engine revision a48a1f07b8
        • Dart version 3.8.0 (build 3.8.0-246.0.dev)
        • DevTools version 2.45.0-dev.0
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [√] Windows Version (11 Home 64-bit, 24H2, 2009) [5.1s]
    
    [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [6.8s]
        • Android SDK at C:\Users\Deana\AppData\Local\Android\sdk
        • Platform android-35, build-tools 34.0.0
        • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
          This is the JDK bundled with the latest Android Studio installation on this machine.
          To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment (build 17.0.7+0-b2043.56-10550314)
        • All Android licenses accepted.
    
    [√] Chrome - develop for the web [175ms]
        • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
    
    [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.2) [171ms]
        • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
        • Visual Studio Community 2022 version 17.8.34322.80
        • Windows 10 SDK version 10.0.22621.0
    
    [√] Android Studio (version 2023.1) [36ms]
        • Android Studio at C:\Program Files\Android\Android Studio
        • 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 17.0.7+0-b2043.56-10550314)
    
    [√] VS Code (version 1.98.0) [32ms]
        • VS Code at C:\Users\Deana\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.106.0
    
    [√] Connected device (3 available) [603ms]
        • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26100.3194]
        • Chrome (web)      • chrome  • web-javascript • Google Chrome 133.0.6943.142
        • Edge (web)        • edge    • web-javascript • Microsoft Edge 134.0.3124.93
    
    [√] Network resources [1,561ms]
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
    
  2. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    platform-windowsBuilding on or for Windows specifically
    f: gesturesflutter/packages/flutter/gestures repository.
    a: mouseIssues related to using a mouse or mouse support
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-windowsOwned by the Windows platform team
    and removed
    in triagePresently being triaged by the triage team
    on Apr 1, 2025
  3. added and removed
    team-windowsOwned by the Windows platform team
    on Apr 28, 2025
  4. added
    P2Important issues not at the top of the work list
    on Jun 5, 2025
  5. CodeDoctorDE commented on Jun 23, 2026

    @CodeDoctorDE
    Contributor

    I think that's exactly the issues for me. I'm working on a fix and contribute it if its working :)

  6. added a commit that references this issue on Jul 23, 2026
    2b9bbc8
  7. github-actions commented on Aug 6, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  8. locked as resolved and limited conversation to collaborators on Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: mouseIssues related to using a mouse or mouse supportf: gesturesflutter/packages/flutter/gestures repository.found in release: 3.29Found to occur in 3.29found in release: 3.31Found to occur in 3.31frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-windowsBuilding on or for Windows specificallyteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions