Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CP-stable][web:semantics] fix double click due to long-press (#54735)
This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/blob/main/docs/releases/Flutter-Cherrypick-Process.md#automatically-creates-a-cherry-pick-request) Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request. ### Issue Link: What is the link to the issue this cherry-pick is addressing? flutter/flutter#147050 ### Changelog Description: Explain this cherry pick in one line that is accessible to most Flutter developers. See [best practices](https://github.com/flutter/flutter/blob/main/docs/releases/Hotfix-Documentation-Best-Practices.md) for examples When semantics are enabled on Web, the `onTap` of various widgets (`GestureDetector`, `InkWell`) are called twice or the callback from one widget is called when another widget is pressed. ### Impact Description: What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)? Does it impact development (ex. flutter doctor crashes when Android Studio is installed), or the shipping production app (the app crashes on launch) This causes multiple issues, e.g I have an `InputField` and a `InkWell` within the same page, tapping on the InputField executes the callback of the `InkWell`. ### Workaround: Is there a workaround for this issue? The workaround is to go through all clickable components and set `excludeFromSemantics: true`. Note that this is not always feasible when using external packages (those you don't have control over). ### Risk: What is the risk level of this cherry-pick? ### Test Coverage: Are you confident that your fix is well-tested by automated tests? ### Validation Steps: What are the steps to validate that this fix works? #### Steps to validate 1. Run the sample code below 2. Tap ONCE on the button #### Expected results The on tap callback is called once and `onTap` is printed once on the console: ```dart onTap ``` #### Code sample <details open><summary>Code sample</summary> ```dart import 'package:flutter/material.dart'; import 'package:flutter/rendering.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); SemanticsBinding.instance.ensureSemantics(); runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @OverRide Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, home: Semantics( enabled: true, child: Scaffold( body: Center( child: GestureDetector( onTap: () => print('onTap'), child: const Text('Click me'), ), ), ), ), ); } } ``` </details>
- Loading branch information