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

[BUG] Tap relative offsets are incorrect when the widget is within a scaling widget #1675

Closed
bramp opened this issue Oct 2, 2023 · 0 comments · Fixed by #1676
Closed

[BUG] Tap relative offsets are incorrect when the widget is within a scaling widget #1675

bramp opened this issue Oct 2, 2023 · 0 comments · Fixed by #1676
Labels
bug This issue reports broken functionality or another error P: 2 (soon™?)

Comments

@bramp
Copy link
Contributor

bramp commented Oct 2, 2023

What is the bug?

When the map is inside a scaling widget, such as Transform.scale(... child: FlutterMap(...)) the onTap gestures are not scaled correctly, leading to both the onTap(TapPosition tapPosition, LatLng point) being slightly the wrong place, even though the map looks correct.

This seems to be due to PositionedTapDetector2._getTapPositions translating the global coordinates to local coordinates, but not correctly scaling them.

How can we reproduce it?

testWidgets('Test tap is detected where expected with scale and offset.',
      (tester) async {
    const screenSize = Size(400, 400);
    await tester.binding.setSurfaceSize(screenSize);

    Offset? lastTap;
    // The Transform.scale fills the screen, but the PositionedTapDetector2
    // occupies the center, with height of 200 (0.5 * 400) and width 400.
    final widget = Transform.scale(
      scaleY: 0.5,
      child: PositionedTapDetector2(
        onTap: (position) => lastTap = position.relative,
        child: SizedBox(
          width: screenSize.width,
          height: screenSize.height,
          child: Container(
            color: Colors.red,
          ),
        ),
      ),
    );

    await tester.pumpWidget(widget);

    // On the screen the PositionedTapDetector2 is actually 400x200, but the
    // widget thinks its 400x400.
    expect(screenSize, tester.getSize(find.byType(SizedBox)));

    Future<void> tap(Offset pos, Offset expected) async {
      lastTap = null;
      await tester.tapAt(pos);
      expect(lastTap, expected);
    }

    // Tap top left of PositionedTapDetector2 which should be 0,0.
    await tap(const Offset(0, 100), Offset.zero);

    // Tap bottom right of PositionedTapDetector2
    await tap(const Offset(400 - 1, 300 - 0.5),
        Offset(screenSize.width - 1, screenSize.height - 1));
  });

Do you have a potential solution?

Yes, #1676

Platforms

Tested on Chrome (Web) and Android.

Severity

Obtrusive: Prevents normal functioning but causes no errors in the console

@bramp bramp added bug This issue reports broken functionality or another error needs triage This new bug report needs reproducing and prioritizing labels Oct 2, 2023
@JaffaKetchup JaffaKetchup added P: 2 (soon™?) and removed needs triage This new bug report needs reproducing and prioritizing labels Oct 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue reports broken functionality or another error P: 2 (soon™?)
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants