Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long press stop sending gesture callbacks #25610

Closed
awoisoak opened this issue Dec 20, 2018 · 7 comments
Closed

Long press stop sending gesture callbacks #25610

awoisoak opened this issue Dec 20, 2018 · 7 comments
Labels
f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels. waiting for PR to land (fixed) A fix is in flight

Comments

@awoisoak
Copy link

awoisoak commented Dec 20, 2018

Steps to Reproduce

I can not detect any gesture events when the user moves the finger during a long press.
I run some code while the user make a long press on a button and detect when it's finishes.

As long as the finger does not move around everything works well as the widget receives the expected callbacks : onLongPress & onLongPressUp.
However, if the user moves the finger while doing the long press, there won't be any other future callback at all.

Sample app: main.dart

If the finger doesn't reach the widget borders I'd expect the onLongPressUp when the finger is up.
If the finger gets out of the widget layout I'd expect the widget to keep listening the gesture events OR receive a onLongPressCanceled callback

[✓] Flutter (Channel beta, v1.0.0, on Mac OS X 10.14 18A391, locale en-JP)
    • Flutter version 1.0.0 at /Users/awo/Library/flutter
    • Framework revision 5391447fae (3 weeks ago), 2018-11-29 19:41:26 -0800
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[✓] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at /Users/awo/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.1, Build version 10B61
    • ios-deploy 2.0.0
    • CocoaPods version 1.5.3

[✓] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 30.0.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

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

[✓] Connected device (1 available)
    • SM N950U1 • ce091719b066e07e0d7e • android-arm64 • Android 8.0.0 (API 26)

• No issues found!

@zoechi zoechi added framework flutter/packages/flutter repository. See also f: labels. f: gestures flutter/packages/flutter/gestures repository. labels Dec 20, 2018
@zoechi zoechi added this to the Goals milestone Dec 20, 2018
@zoechi zoechi added the waiting for PR to land (fixed) A fix is in flight label Dec 20, 2018
@zoechi
Copy link
Contributor

zoechi commented Dec 21, 2018

Looks related to #11385

@SinaSeirafi
Copy link

SinaSeirafi commented Jan 28, 2019

I'm facing the same problem.
Instead of using Horizontal or Vertical drags, I tried using onPanEnd and onScaleEnd to no end.

And that's a bit disappointing. Considering the description for onPanEnd is: "A pointer that was previously in contact with the screen and moving is no longer in contact with the screen and was moving at a specific velocity when it stopped contacting the screen."

It seems like when onLongPress is detected the only other gesture that can be detected is onLongPressUp and only when the pointer doesn't move, and onPanStart is not called when the pointer starts moving, despite the description: "A pointer has contacted the screen and has begun to move."

This is my code if it can be helpful. A long press changes the color of the box and canceling it reverts it back.

import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      title: "Markdown Demo",
      theme: ThemeData(primarySwatch: Colors.lightGreen),
      home: HomePage(),
    ),
  );
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  Color myColor = Colors.lightBlueAccent;

  Widget _buildtest() {
    _longPressUp() {
      setState(() {
        myColor = Colors.lightBlueAccent;
      });
      print('-- Back to main color');
    }

    return Center(
      child: Container(
        color: myColor,
        width: 300,
        height: 300,
        child: GestureDetector(
          onTap: () {},
          onTapUp: (_) {
            print('onTap Up');
            _longPressUp();
          },
          onLongPress: () {
            print('LongPress');
            print('-> Changing Color');
            setState(() {
              myColor = Colors.limeAccent;
            });
          },
          onLongPressUp: () {
            print('LongPress Up');
            _longPressUp();
          },

          // ---> Either use onPan or onScale

          // onScaleEnd: (_) {
          //   print('Scale End');
          // _longPressUp();
          // },

          // for checking when an onScale is detected
          // onScaleStart: (details) {
          // print('Scale Started: $details');
          // },

          onPanEnd: (_) {
            print('Pan End');
            _longPressUp();
          },

          // for checking when an onPan is detected
          onPanStart: (details) {
            print('Pan Started: $details');
          },
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          'Long press Up detection',
          style: TextStyle(
            color: Colors.white,
          ),
        ),
      ),
      body: _buildtest(),
    );
  }
}

@xster
Copy link
Member

xster commented Jul 31, 2019

We're talking about this behavior right?

testGesture('Moving after accept does not cancel', (GestureTester tester) {

It should work.

If you move before a long press is recognized, it's by definition not a long press :D

testGesture('Moving before accept cancels', (GestureTester tester) {

@tapizquent
Copy link

Any updates on this? I really need an option to show a widget on long press and then hide it when they release

@marcglasberg
Copy link

marcglasberg commented Nov 3, 2019

I can not detect onPanUpdate while the user is doing a LongPress. Is that expected behavior? It seems I should then use onLongPressMoveUpdate but onPanUpdate's documentation doesn't say it doesn't work during a LongPress. Also onPanUpdate is much easier to use with certain use cases, since it gives you dx/dy, and onLongPressMoveUpdate does not.

I'd say the GestureDetector in Flutter needs improvement. I believe the documentation should be redone, with all the necessary details, and also all update callbacks should inform dx/dy, not only the current pointer position.

@iapicca
Copy link
Contributor

iapicca commented Mar 27, 2020

Hi @awoisoak
I see there's an open issue addressing the case you described.
Please follow up on that issue,
I'm closing the current one as duplicate.
If you disagree please write in the comments
and I will reopen it.
Thank you

@iapicca iapicca closed this as completed Mar 27, 2020
@lock
Copy link

lock bot commented Apr 19, 2020

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.

@lock lock bot locked and limited conversation to collaborators Apr 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels. waiting for PR to land (fixed) A fix is in flight
Projects
None yet
Development

No branches or pull requests

7 participants