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

Incorrect position in first update from MultiDragGestureRecognizer #117146

Open
tgucio opened this issue Dec 15, 2022 · 4 comments
Open

Incorrect position in first update from MultiDragGestureRecognizer #117146

tgucio opened this issue Dec 15, 2022 · 4 comments
Labels
c: new feature Nothing broken; request for a new capability f: gestures flutter/packages/flutter/gestures repository. found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P3 Issues that are less important to the Flutter project team-framework Owned by Framework team triaged-framework Triaged by Framework team

Comments

@tgucio
Copy link
Contributor

tgucio commented Dec 15, 2022

Steps to Reproduce

  1. Execute flutter run on the code sample to run on a phone
  2. Try a few drag gestures (with and without holding the finger down for a while first)

Expected results: The first drag update carries a different offset from the one supplied to the onStart callback

Actual results: The first drag update always has the same offset as in onStart callback despite delta being correct. Additionally, the DragUpdateDetails.localPosition field isn't provided meaning it will default to .globalPosition so it can't be relied on.

I/flutter (30743): _handleDragStart Offset(157.4, 413.1)
I/flutter (30743): _handleDragUpdate localPosition=Offset(157.4, 413.1) globalPosition=Offset(157.4, 413.1) delta=Offset(14.3, -13.7) primaryDelta=null
I/flutter (30743): _handleDragUpdate localPosition=Offset(173.7, 398.0) globalPosition=Offset(173.7, 398.0) delta=Offset(2.0, -1.4) primaryDelta=null
I/flutter (30743): _handleDragEnd
I/flutter (30743): _handleTapDown Offset(128.6, 227.4)
I/flutter (30743): _handleDragStart Offset(134.3, 409.1)
I/flutter (30743): _handleDragUpdate localPosition=Offset(134.3, 409.1) globalPosition=Offset(134.3, 409.1) delta=Offset(11.1, -14.3) primaryDelta=null
I/flutter (30743): _handleDragUpdate localPosition=Offset(148.0, 392.6) globalPosition=Offset(148.0, 392.6) delta=Offset(2.6, -2.3) primaryDelta=null
I/flutter (30743): _handleDragUpdate localPosition=Offset(150.6, 390.3) globalPosition=Offset(150.6, 390.3) delta=Offset(2.6, -2.3) primaryDelta=null
I/flutter (30743): _handleDragUpdate localPosition=Offset(152.9, 388.3) globalPosition=Offset(152.9, 388.3) delta=Offset(2.3, -2.0) primaryDelta=null
I/flutter (30743): _handleDragUpdate localPosition=Offset(154.6, 386.9) globalPosition=Offset(154.6, 386.9) delta=Offset(1.7, -1.4) primaryDelta=null
I/flutter (30743): _handleDragUpdate localPosition=Offset(156.0, 385.7) globalPosition=Offset(156.0, 385.7) delta=Offset(1.4, -1.1) primaryDelta=null
I/flutter (30743): _handleDragUpdate localPosition=Offset(157.1, 384.6) globalPosition=Offset(157.1, 384.6) delta=Offset(1.1, -1.1) primaryDelta=null
I/flutter (30743): _handleDragUpdate localPosition=Offset(158.0, 383.7) globalPosition=Offset(158.0, 383.7) delta=Offset(0.9, -0.9) primaryDelta=null
I/flutter (30743): _handleDragUpdate localPosition=Offset(158.9, 383.1) globalPosition=Offset(158.9, 383.1) delta=Offset(0.9, -0.6) primaryDelta=null
I/flutter (30743): _handleDragUpdate localPosition=Offset(160.3, 382.3) globalPosition=Offset(160.3, 382.3) delta=Offset(1.4, -0.9) primaryDelta=null
I/flutter (30743): _handleDragEnd
Code sample
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  void _handleTapDown(TapDownDetails details) {
    print('_handleTapDown ${details.localPosition}');
  }

  void _handleTapUp(TapUpDetails details) {
    print('_handleTapUp ${details.localPosition}');
  }
 
  Drag? _handleDragStart(Offset position) {
    print('_handleDragStart $position');
    return _DragHandler(_handleDragUpdate, _handleDragCancel, _handleDragEnd);
  }

  void _handleDragUpdate(DragUpdateDetails details) {
    print('_handleDragUpdate localPosition=${details.localPosition} globalPosition=${details.globalPosition} '
        'delta=${details.delta} primaryDelta=${details.primaryDelta}');
  }

  void _handleDragCancel() {
    print('_handleDragCancel');
  }

  void _handleDragEnd(DragEndDetails details) {
    print('_handleDragEnd');
  }

  @override
  Widget build(BuildContext context) {
    final Map<Type, GestureRecognizerFactory> gestures = <Type, GestureRecognizerFactory>{
      TapGestureRecognizer: GestureRecognizerFactoryWithHandlers<TapGestureRecognizer>(
        () => TapGestureRecognizer(debugOwner: this),
        (TapGestureRecognizer instance) {
          instance
            ..onTapDown = _handleTapDown
            ..onTapUp = _handleTapUp;
        },
      ),
      ImmediateMultiDragGestureRecognizer: GestureRecognizerFactoryWithHandlers<ImmediateMultiDragGestureRecognizer>(
        () => ImmediateMultiDragGestureRecognizer(debugOwner: this),
        (ImmediateMultiDragGestureRecognizer instance) {
          instance.onStart = _handleDragStart;
        },
      ),
    };

    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: Center(
        child: Container(
          width: 400.0,
          height: 400.0,
          color: Colors.red,
          child: RawGestureDetector(
            gestures: gestures,
          ),
        ),
      ),
    );
  }
}

class _DragHandler extends Drag {
  _DragHandler(this.onUpdate, this.onCancel, this.onEnd);

  final GestureDragUpdateCallback onUpdate;
  final GestureDragCancelCallback onCancel;
  final GestureDragEndCallback onEnd;

  @override
  void update(DragUpdateDetails details) {
    onUpdate(details);
  }

  @override
  void cancel() {
    onCancel();
  }

  @override
  void end(DragEndDetails details) {
    onEnd(details);
  }
}
Logs
@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Dec 16, 2022
@darshankawar
Copy link
Member

Thanks for the report @tgucio
Running your code sample on latest master using iOS simulator gives me the expected result, ie, the _handleDragStart and first _handleDragUpdate offset is same:

flutter: _handleTapDown Offset(224.3, 171.2)
flutter: _handleDragStart Offset(238.3, 485.7)
flutter: _handleDragUpdate localPosition=Offset(238.3, 485.7) globalPosition=Offset(238.3, 485.7) delta=Offset(-4.3, -22.3) primaryDelta=null
flutter: _handleDragUpdate localPosition=Offset(231.0, 451.3) globalPosition=Offset(231.0, 451.3) delta=Offset(-3.0, -12.0) primaryDelta=null

Channel master, 3.7.0-10.0.pre.15

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 16, 2022
@tgucio
Copy link
Contributor Author

tgucio commented Dec 16, 2022

Hi @darshankawar the two offsets should be different (note the non-zero delta in the first _handleDragUpdate).
Also, localPosition == globalPosition which should not be the case unless the widget is located at Offset(0, 0).

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Dec 16, 2022
@darshankawar
Copy link
Member

Thanks for the update.

stable, master flutter doctor -v
[✓] Flutter (Channel stable, 3.3.10, on macOS 12.2.1 21D62 darwin-x64, locale
    en-GB)
    • Flutter version 3.3.10 on channel stable at
      /Users/dhs/documents/fluttersdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 135454af32 (15 hours ago), 2022-12-15 07:36:55 -0800
    • Engine revision 3316dd8728
    • Dart version 2.18.6
    • DevTools version 2.15.0

[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

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

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

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

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

! Doctor found issues in 1 category.

[!] Flutter (Channel master, 3.7.0-10.0.pre.15, on macOS 12.2.1 21D62
    darwin-x64, locale en-GB)
    • Flutter version 3.7.0-10.0.pre.15 on channel master at
      /Users/dhs/documents/fluttersdk/flutter
    ! Warning: `flutter` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/flutter, which is not inside
      your current Flutter SDK checkout at
      /Users/dhs/documents/fluttersdk/flutter. Consider adding
      /Users/dhs/documents/fluttersdk/flutter/bin to the front of your path.
    ! Warning: `dart` on your path resolves to
      /Users/dhs/Documents/Fluttersdk/flutter/bin/dart, which is not inside your
      current Flutter SDK checkout at /Users/dhs/documents/fluttersdk/flutter.
      Consider adding /Users/dhs/documents/fluttersdk/flutter/bin to the front
      of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 76bb8ead5a (62 minutes ago), 2022-12-15 19:38:53 -0800
    • Engine revision 29196519c1
    • Dart version 3.0.0 (build 3.0.0-21.0.dev)
    • DevTools version 2.20.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.


[!] Xcode - develop for iOS and macOS (Xcode 12.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    ! Flutter recommends a minimum Xcode version of 13.
      Download the latest version or update via the Mac App Store.
    • CocoaPods version 1.11.2

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

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

[✓] Connected device (5 available)
    • SM G975F (mobile)       • RZ8M802WY0X • android-arm64   • Android 11 (API 30)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 98.0.4758.80

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

! Doctor found issues in 1 category.



@darshankawar darshankawar added framework flutter/packages/flutter repository. See also f: labels. f: gestures flutter/packages/flutter/gestures repository. has reproducible steps The issue has been confirmed reproducible and is ready to work on found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 and removed in triage Presently being triaged by the triage team labels Dec 16, 2022
@goderbauer
Copy link
Member

For the DragGestureRecognizer you should be able to control this via the dragStartBehavior. Looks like we don't have this as an option for the MultiDragGestureRecognizer, though.

@goderbauer goderbauer added c: new feature Nothing broken; request for a new capability P3 Issues that are less important to the Flutter project labels Dec 20, 2022
@flutter-triage-bot flutter-triage-bot bot added team-framework Owned by Framework team triaged-framework Triaged by Framework team labels Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: new feature Nothing broken; request for a new capability f: gestures flutter/packages/flutter/gestures repository. found in release: 3.3 Found to occur in 3.3 found in release: 3.7 Found to occur in 3.7 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P3 Issues that are less important to the Flutter project team-framework Owned by Framework team triaged-framework Triaged by Framework team
Projects
None yet
Development

No branches or pull requests

3 participants