Skip to content

Hidden child widget of IndexedStack can be focused when using Tab shortcut key. #114213

@MegatronKing

Description

@MegatronKing

Steps to Reproduce

  1. Execute flutter run on the code sample
  2. There are two buttons, one is on the left side, another is on the right side but invisible.
  3. Tap the 'Tab' key on keyboard to switch the focus and tap 'Enter' key to trigger the button.

Expected results: The hiden button should not gain the focus and be triggerred.

Actual results: The hiden button will gain focus and be triggerred.

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't 
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      appBar: AppBar(
        // Here we take the value from the MyHomePage object that was created by
        // the App.build method, and use it to set our appbar title.
        title: Text(widget.title),
      ),
      body: IndexedStack(
        index: 0,
        children: [
          Container(
            // color: Colors.yellow,
            alignment: Alignment.centerLeft,
            child: InkWell(
              focusColor: Colors.red,
              onTap: () {
                print("Button 1 clicked");
              },
              child: const Text("Button 1"),
            ),
          ),
          Container(
            // color: Colors.blue,
            alignment: Alignment.centerRight,
            child: InkWell(
              focusColor: Colors.red,
              onTap: () {
                print("Button 2 clicked");
              },
              child: const Text("Button 2"),
            ),
          )
        ],
      ),
    );
  }
}
Logs
[✓] Flutter (Channel stable, 3.0.4, on macOS 12.1 21C52 darwin-x64, locale en-CN)
    • Flutter version 3.0.4 at /Users/megatronking/Github/flutter
    • Upstream repository https://gitee.com/mirrors/Flutter.git
    • Framework revision 85684f9300 (4 months ago), 2022-06-30 13:22:47 -0700
    • Engine revision 6ba2af10bb
    • Dart version 2.17.5
    • DevTools version 2.12.2

Checking Android licenses is taking an unexpectedly long time...[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/megatronking/Library/Android/sdk
    • Platform android-31, build-tools 31.0.0
    • ANDROID_HOME = /Users/megatronking/Library/Android/sdk
    • ANDROID_SDK_ROOT = /Users/megatronking/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
    • 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 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-7281165)

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

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-x64     • macOS 12.1 21C52 darwin-x64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 106.0.5249.119
Screen.Recording.2022-10-28.at.2.07.19.PM.mov

Metadata

Metadata

Labels

P2Important issues not at the top of the work lista: desktopRunning on desktopcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.f: focusFocus traversal, gaining or losing focusfound in release: 3.3Found to occur in 3.3found in release: 3.4Found to occur in 3.4frameworkflutter/packages/flutter repository. See also f: labels.fyi-accessibilityFor the attention of Framework Accessibility teamhas reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions