Repository navigation
Update the documentation of Semantics' onLongPress #35112
Description
Activity
- addeda: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)Accessibility, e.g. VoiceOver or TalkBack. (aka a11y)frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.
on Jun 26, 2019 - changed the title
[-]Semantics' onLongPress doesn't get triggered without showSemanticsDebugger[/-][+]Semantics' onLongPress doesn't get triggered without setting MaterialApp.showSemanticsDebugger[/+]on Jan 9, 2020 Reproducible on the latest master
1.21.0-6.0.pre.191.Minimal reproducible code sample
import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( //This makes onLongPress work //showSemanticsDebugger: true, title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: MyHomePage(), ); } } class MyHomePage extends StatefulWidget { @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { int _counter = 0; void _incrementCounter() { setState(() { _counter++; }); } void _decrementCounter() { setState(() { _counter--; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Sample'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: <Widget>[ Text( 'You have pushed the button this many times:', ), Semantics( label: 'Counter button', hint: 'Press to increase', value: '$_counter', onTap: _incrementCounter, onLongPress: _decrementCounter, child: ExcludeSemantics( child: Text( '$_counter', style: Theme.of(context).textTheme.display1, ), ), ), ], ), ), ); } }flutter doctor -v
[✓] Flutter (Channel master, 1.21.0-6.0.pre.191, on Mac OS X 10.15.6 19G73, locale en-GB) • Flutter version 1.21.0-6.0.pre.191 at /Users/markus/development/flutter_master • Framework revision f3b7788f77 (5 hours ago), 2020-08-05 00:11:03 -0400 • Engine revision e1828008b9 • Dart version 2.10.0 (build 2.10.0-3.0.dev 987c9e347c) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1) • Android SDK at /Users/markus/Library/Android/sdk • Platform android-30, build-tools 30.0.1 • Java binary at: /Users/markus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/193.6626763/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 11.6) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 11.6, Build version 11E708 • CocoaPods version 1.9.3 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.0) • Android Studio at /Users/markus/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/193.6626763/Android Studio.app/Contents • Flutter plugin version 48.0.2 • Dart plugin version 193.7361 • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593) [✓] Connected device (5 available) • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator) • Nevercode’s iPhone (mobile) • b668e524315069f3db3661ac11ff1f66afafebdb • ios • iOS 13.6 • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.6 19G73 • Web Server (web) • web-server • web-javascript • Flutter Tools • Chrome (web) • chrome • web-javascript • Google Chrome 84.0.4147.105 • No issues found!- addedfound in release: 1.21Found to occur in 1.21Found to occur in 1.21has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work on
on Aug 5, 2020 - addedP2Important issues not at the top of the work listImportant issues not at the top of the work listc: regressionIt was better in the past than it is nowIt was better in the past than it is now
on Jan 22, 2022 Reproducible on the latest master 2.9.0-1.0.pre.452.
Semantics( onLongPress: () { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Semantics onLongPress called.')), ); }, onLongPressHint: 'call snackbar', child: const Text('Test semantics', style: TextStyle(fontSize: 50)), )
showSemanticsDebuggerfalseRecord_2022-01-22-16-19-05_addc32bca73e9f6027afbb.mp4
showSemanticsDebuggertrueRecord_2022-01-22-16-20-23_addc32bca73e9f6027afbb.mp4
flutter doctor -v
[✓] Flutter (Channel master, 2.9.0-1.0.pre.452, on Microsoft Windows [Version 10.0.22000.434], locale zh-CN) • Flutter version 2.9.0-1.0.pre.452 at X:\SDK\flutter-master • Upstream repository https://github.com/AlexV525/flutter • Framework revision da7d7777e2 (3 hours ago), 2022-01-22 00:20:19 -0500 • Engine revision 5061c0fb74 • Dart version 2.17.0 (build 2.17.0-44.0.dev) • DevTools version 2.9.2/cc @chunhtai
Workaround for TalkBack:
Widget _buildSemantics(BuildContext context) { void _onLongPress() { // Implement your own call. print('onLongPress'); } return Semantics( onLongPress: _onLongPress, onLongPressHint: 'call something', child: GestureDetector( onLongPress: MediaQuery.of(context).accessibleNavigation ? _onLongPress : null, child: const Text('Test Semantics onLongPress'), ), ); }
voiceover sends the long press directly to the application instead of semantics action. you need to use gesture recognizer in this case.
closing this issue
@chunhtai This also happened to Talkback, see screen records above. Now they behave the same. I don't think there is a platform regression, but the framework might do.
@chunhtai The documentation for SemanticsProperties.onLongPress [permalink] says:
VoiceOver users on iOS and TalkBack users on Android can trigger this action by double-tapping the screen without lifting the finger after the second tap.
So I believe that this is intended to to work on both VoiceOver and TalkBack, and if it's not the intention, then it should not have such documentation.
/cc @goderbauer who originally wrote the doc. [blame ref]
We can't control how the platform decide to interpret the accessibility long press, it looks like in some case they are sent through semantics action and sometimes it synthesizes a screen long press. We need to update the documentation.
- addedd: api docsIssues with https://api.flutter.dev/Issues with https://api.flutter.dev/and removedd: api docsIssues with https://api.flutter.dev/Issues with https://api.flutter.dev/
on Jan 25, 2022 - changed the title
[-]Semantics' onLongPress doesn't get triggered without setting MaterialApp.showSemanticsDebugger[/-][+]Update the documentation of Semantics' onLongPress[/+]on Jan 25, 2022 - removedc: regressionIt was better in the past than it is nowIt was better in the past than it is now
on Jan 28, 2022 - added a commit that references this issue
on Jun 9, 2023 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 -vand a minimal reproduction of the issue.- locked as resolved and limited conversation to collaborators
on Jun 23, 2023
Steps to Reproduce
A working repro is located at https://github.com/kpsroka/flutter_accessibility_demo/tree/onLongPress-Bug (notice the tag)
The core part of the problem is the following:
Observed:
onTaphandler is being executed, whileonLongPresshandler isn't.However, when you enable semantics debugger (uncomment this line), you'll be able to trigger the
onLongPresshandler.Logs
flutter run --verbosewithout SemanticsDebuggerflutter run --verbosewith SemanticsDebuggerNotice that I removed the
debugPrintstatements from the code before executing the above commands.