Skip to content

Update the documentation of Semantics' onLongPress #35112

Description

@kpsroka

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:

Semantics(
  label: 'Counter button',
  hint: 'Press to increase',
  value: '$_counter',
  enabled: true,
  container: true,
  excludeSemantics: true,
  onTap: _incrementCounter,
  onLongPress: _decrementCounter,
  child: Text(
    '$_counter',
    style: Theme.of(context).textTheme.display1,
  )),
  1. Launch on an iOS device with VoiceOver enabled, or on an Android device with TalkBack enabled.
  2. Launch the project mentioned above.
  3. Move focus to the counter number. Double-tap to trigger the "tap" handler, double-tap & hold to trigger the "long press" handler.

Observed:

  • onTap handler is being executed, while onLongPress handler isn't.

However, when you enable semantics debugger (uncomment this line), you'll be able to trigger the onLongPress handler.

Logs

flutter run --verbose without SemanticsDebugger

flutter run --verbose with SemanticsDebugger

Notice that I removed the debugPrint statements from the code before executing the above commands.

$ flutter doctor -v
[✓] Flutter (Channel beta, v1.6.3, on Mac OS X 10.14.5 18F132, locale en-PL)
    • Flutter version 1.6.3 at /Users/krzysztofsroka/Library/Flutter
    • Framework revision bc7bc94083 (5 weeks ago), 2019-05-23 10:29:07 -0700
    • Engine revision 8dc3a4cde2
    • Dart version 2.3.2 (build 2.3.2-dev.0.0 e3edfd36b2)

 
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /Users/krzysztofsroka/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = /Users/krzysztofsroka/Library/Android/sdk
    • 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.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 10.2.1, Build version 10E1001
    • ios-deploy 1.9.4
    • CocoaPods version 1.6.1

[!] Android Studio (version 3.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

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

[✓] Connected device (1 available)
    • CK test • 7fd603d4b73339426ca23d745840a51dfcfbaecc • ios • iOS 12.2

! Doctor found issues in 1 category.

Activity

  1. added
    a: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Jun 26, 2019
  2. 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
  3. markusaksli-nc commented on Aug 5, 2020

    @markusaksli-nc
    Contributor

    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!
    
  4. added
    P2Important issues not at the top of the work list
    c: regressionIt was better in the past than it is now
    on Jan 22, 2022
  5. AlexV525 commented on Jan 22, 2022

    @AlexV525
    Member

    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)),
    )

    showSemanticsDebugger false

    Record_2022-01-22-16-19-05_addc32bca73e9f6027afbb.mp4

    showSemanticsDebugger true

    Record_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
    
  6. AlexV525 commented on Jan 22, 2022

    @AlexV525
    Member
  7. AlexV525 commented on Jan 22, 2022

    @AlexV525
    Member

    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'),
        ),
      );
    }
  8. self-assigned this
    on Jan 24, 2022
  9. chunhtai commented on Jan 24, 2022

    @chunhtai
    Contributor

    voiceover sends the long press directly to the application instead of semantics action. you need to use gesture recognizer in this case.

  10. chunhtai commented on Jan 24, 2022

    @chunhtai
    Contributor

    closing this issue

  11. AlexV525 commented on Jan 25, 2022

    @AlexV525
    Member

    @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.

  12. kpsroka commented on Jan 25, 2022

    @kpsroka
    ContributorAuthor

    @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.

  13. AlexV525 commented on Jan 25, 2022

    @AlexV525
    Member

    /cc @goderbauer who originally wrote the doc. [blame ref]

  14. chunhtai commented on Jan 25, 2022

    @chunhtai
    Contributor

    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.

  15. added
    d: api docsIssues with https://api.flutter.dev/
    and removed
    d: api docsIssues with https://api.flutter.dev/
    on Jan 25, 2022
  16. changed the title [-]Semantics' onLongPress doesn't get triggered without setting MaterialApp.showSemanticsDebugger[/-] [+]Update the documentation of Semantics' onLongPress[/+] on Jan 25, 2022
  17. github-actions commented on Jun 23, 2023

    @github-actions

    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.

  18. locked as resolved and limited conversation to collaborators on Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)found in release: 1.21Found to occur in 1.21found in release: 2.9Found to occur in 2.9frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work on

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions