Skip to content

[Semantics][Android]: Focus do not return to the top of the page when starting a new page #97522

Closed

Description

@guinardA

My application contains navigator, and when I push a new page with a button located in my bottomNavigationBar of my Scaffold and my new page also has a button in bottomNavigationBar. My focus remains on the button of the bottomNavigationBar of my new page on Android and does not automatically return to appBar like in iOS.

Steps to Reproduce
Using the following example app:

import 'package:flutter/material.dart';

void main() {
  runApp(const MaterialApp(
    title: 'Navigation Basics',
    home: FirstRoute(),
  ));
}

class FirstRoute extends StatelessWidget {
  const FirstRoute({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('First Route'),
      ),
      body: const Center(child: Text('Page One')),
      bottomNavigationBar: ElevatedButton(
        child: const Text('Page two'),
        onPressed: () {
          Navigator.push(
            context,
            MaterialPageRoute(builder: (context) => const SecondRoute()),
          );
        },
      ),
    );
  }
}

class SecondRoute extends StatelessWidget {
  const SecondRoute({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Second Route'),
      ),
      body: const Center(child: Text('Page Two')),
      bottomNavigationBar: ElevatedButton(
        child: const Text('Page three'),
        onPressed: () {
          Navigator.push(
            context,
            MaterialPageRoute(builder: (context) => const ThirdRoute()),
          );
        },
      ),
    );
  }
}

class ThirdRoute extends StatelessWidget {
  const ThirdRoute({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Third Route'),
      ),
      body: const Center(child: Text('Page Three')),
      bottomNavigationBar: ElevatedButton(
        child: const Text('Page one'),
        onPressed: () {
          Navigator.push(
            context,
            MaterialPageRoute(builder: (context) => const FirstRoute()),
          );
        },
      ),
    );
  }
}
  1. Open the above app with talkback enabled on an Android device.
  2. Swipe to the right to navigate to the bottom button
  3. Double click on my bottom button
  4. Notice that the talkback focus directly on the bottom button of the page two and doesn't automatically return to appBar

The same process on iOS with voiceOver working.

I tried to put a semantics widget with focused to true on appBar. As well as a focusNode, but that doesn't work.

Flutter doctor

[✓] Flutter (Channel stable, 2.8.1, on macOS 11.6 20G165 darwin-x64, locale fr-FR)
    • Flutter version 2.8.1 at /usr/local/Caskroom/flutter/2.8.0/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 77d935af4d (7 weeks ago), 2021-12-16 08:37:33 -0800
    • Engine revision 890a5fca2e
    • Dart version 2.15.1

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/arnaud/Library/Android/sdk
    • Platform android-31, build-tools 30.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

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

[✓] Android Studio (version 4.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)

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

[✓] Connected device (1 available)
    • Chrome (web) • chrome • web-javascript • Google Chrome 97.0.4692.99

• No issues found!

Activity

  1. danagbemava-nc commented on Feb 1, 2022

    @danagbemava-nc
    Member

    Reproducible using code sample and steps in #97522 (comment) on android.
    Unable to confirm iOS behavior at the moment. I will update this post when I'm able to.

    video
    telegram-cloud-document-4-6035086468639100709.mp4
    flutter doctor -v
    [✓] Flutter (Channel stable, 2.8.1, on macOS 11.6.2 20G314 darwin-arm, locale en-GB)
        • Flutter version 2.8.1 at /Users/nexus/dev/sdks/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 77d935af4d (7 weeks ago), 2021-12-16 08:37:33 -0800
        • Engine revision 890a5fca2e
        • Dart version 2.15.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-31, build-tools 31.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.0)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2020.3)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    
    [☠] IntelliJ IDEA Community Edition (the doctor check crashed)
        ✗ Due to an error, the doctor check did not complete. If the error message below is not helpful, please let us know about this issue at https://github.com/flutter/flutter/issues.
        ✗ FormatException: Unexpected extension byte (at offset 5)
        • #0      _Utf8Decoder.convertSingle (dart:convert-patch/convert_patch.dart:1789:7)
          #1      Utf8Decoder.convert (dart:convert/utf.dart:318:42)
          #2      InputStream.readString (package:archive/src/util/input_stream.dart:207:30)
          #3      new ZipDirectory.read (package:archive/src/zip/zip_directory.dart:40:30)
          #4      ZipDecoder.decodeBuffer (package:archive/src/zip_decoder.dart:19:30)
          #5      ZipDecoder.decodeBytes (package:archive/src/zip_decoder.dart:14:12)
          #6      IntelliJPlugins._findPluginXml (package:flutter_tools/src/intellij/intellij.dart:130:44)
          #7      IntelliJPlugins._readPackageVersion (package:flutter_tools/src/intellij/intellij.dart:141:40)
          #8      IntelliJPlugins.validatePackage (package:flutter_tools/src/intellij/intellij.dart:63:35)
          #9      IntelliJValidator.validate (package:flutter_tools/src/intellij/intellij_validator.dart:103:15)
          #10     asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:111:32)
          #11     asyncGuard.<anonymous closure> (package:flutter_tools/src/base/async_guard.dart:109:18)
          #12     _rootRun (dart:async/zone.dart:1428:13)
          #13     _CustomZone.run (dart:async/zone.dart:1328:19)
          #14     _runZoned (dart:async/zone.dart:1863:10)
          #15     runZonedGuarded (dart:async/zone.dart:1851:12)
          #16     runZoned (dart:async/zone.dart:1782:12)
          #17     asyncGuard (package:flutter_tools/src/base/async_guard.dart:109:3)
          #18     Doctor.startValidatorTasks (package:flutter_tools/src/doctor.dart:197:9)
          #19     Doctor.diagnose (package:flutter_tools/src/doctor.dart:301:47)
          #20     DoctorCommand.runCommand (package:flutter_tools/src/commands/doctor.dart:53:47)
          #21     FlutterCommand.verifyThenRunCommand (package:flutter_tools/src/runner/flutter_command.dart:1290:12)
          <asynchronous suspension>
          #22     FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1140:27)
          <asynchronous suspension>
          #23     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
          <asynchronous suspension>
          #24     CommandRunner.runCommand (package:args/command_runner.dart:209:13)
          <asynchronous suspension>
          #25     FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:288:9)
          <asynchronous suspension>
          #26     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
          <asynchronous suspension>
          #27     FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:236:5)
          <asynchronous suspension>
          #28     run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:9)
          <asynchronous suspension>
          #29     AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
          <asynchronous suspension>
          #30     main (package:flutter_tools/executable.dart:94:3)
          <asynchronous suspension>
    
    
    [✓] VS Code (version 1.63.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.32.0
    
    [✓] Connected device (5 available)
        • M2007J20CG (mobile) • 5dd3be00                             • android-arm64  • Android 11 (API 30)
        • Nexus (mobile)      • 00008020-001875E83A38002E            • ios            • iOS 15.3 19D50
        • iPhone 13 (mobile)  • 7515F01A-C1B6-456E-8559-8D2383D3719D • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
        • macOS (desktop)     • macos                                • darwin-arm64   • macOS 11.6.2 20G314 darwin-arm
        • Chrome (web)        • chrome                               • web-javascript • Google Chrome 97.0.4692.99
        ! Error: Nexus is busy: Preparing Nexus for development. Xcode will continue when Nexus is finished. (code -10)
    
    ! Doctor found issues in 1 category.
    [✓] Flutter (Channel master, 2.10.0-1.0.pre.351, on macOS 11.6.2 20G314 darwin-arm, locale en-GB)
        • Flutter version 2.10.0-1.0.pre.351 at /Users/nexus/dev/sdks/flutters
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision c9073beebc (2 hours ago), 2022-02-01 00:15:14 -0500
        • Engine revision 740d1420c8
        • Dart version 2.17.0 (build 2.17.0-69.0.dev)
        • DevTools version 2.10.0-dev.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/nexus/Library/Android/sdk
        • Platform android-31, build-tools 31.0.0
        • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.0)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • CocoaPods version 1.11.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2020.3)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.3)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin version 213.5744.122
    
    [✓] VS Code (version 1.63.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.32.0
    
    [✓] Connected device (5 available)
        • M2007J20CG (mobile) • 5dd3be00                             • android-arm64  • Android 11 (API 30)
        • Nexus (mobile)      • 00008020-001875E83A38002E            • ios            • iOS 15.3 19D50
        • iPhone 13 (mobile)  • 7515F01A-C1B6-456E-8559-8D2383D3719D • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-0 (simulator)
        • macOS (desktop)     • macos                                • darwin-arm64   • macOS 11.6.2 20G314 darwin-arm
        • Chrome (web)        • chrome                               • web-javascript • Google Chrome 97.0.4692.99
        ! Error: Nexus is busy: Preparing Nexus for development. Xcode will continue when Nexus is finished. (code -10)
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
  2. added
    a: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)
    f: focusFocus traversal, gaining or losing focus
    frameworkflutter/packages/flutter repository. See also f: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    platform-androidAndroid applications specifically
    and removed
    in triagePresently being triaged by the triage team
    on Feb 1, 2022
  3. goderbauer commented on Feb 2, 2022

    @goderbauer
    Member
  4. added
    P2Important issues not at the top of the work list
    on Feb 2, 2022
  5. chunhtai commented on Feb 2, 2022

    @chunhtai
    Contributor

    Unfortunately the focus is purely managed by android talkBack, and we don't have control on how they handle it. A few observations i found is they may set the focus at the original location if the layouts of two pages are similar.

  6. luomo-pro commented on Feb 3, 2022

    @luomo-pro

    hi
    @chunhtai
    In #93926, I tested that the native software talk back is able to remember the focus position accurately, only in flutter it is not.
    If you use iOS, you can use VoiceOver's scrub gesture to remember the focus position accurately in the native software.
    So I feel it should still be a problem with flutter, please try to see if there is a way to fix it. I talk about the importance of this issue for blind users in detail in #93926, it is important.

  7. luomo-pro commented on Feb 3, 2022

    @luomo-pro

    @chunhtai
    If flutter's UI cannot support talk back to automatically remember focus.
    Then is it possible to try to solve #94523 by providing an API to manually get as well as set accessibility focus, so that developers can manually support focus memory?

  8. jscti commented on Feb 3, 2022

    @jscti

    +1 for the reopening of this

  9. chunhtai commented on Feb 3, 2022

    @chunhtai
    Contributor

    There is #94523 to better manage the focus in Flutter. If that is done, Flutter should remember the focus on a visited page in both iOS and Android more accurately, and programmatically adjust the focus.

  10. github-actions commented on Feb 17, 2022

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

  11. locked as resolved and limited conversation to collaborators on Feb 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)f: focusFocus traversal, gaining or losing focusfound in release: 2.10Found to occur in 2.10found in release: 2.8Found to occur in 2.8frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onplatform-androidAndroid applications specificallyr: invalidIssue is closed as not valid

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions