Repository navigation
Closed
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listfound in release: 2.2Found to occur in 2.2Found to occur in 2.2frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Description
When focusing a widget using requestFocus, the focus traversal with the arrow keys is unintuitive.
Steps to Reproduce
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Focus Traversal Bug',
home: Shortcuts(
shortcuts: {
// Focus traversal using keyboard is not enabled by default on the web
LogicalKeySet(LogicalKeyboardKey.arrowLeft):
const DirectionalFocusIntent(TraversalDirection.left),
LogicalKeySet(LogicalKeyboardKey.arrowRight):
const DirectionalFocusIntent(TraversalDirection.right),
LogicalKeySet(LogicalKeyboardKey.arrowDown):
const DirectionalFocusIntent(TraversalDirection.down),
LogicalKeySet(LogicalKeyboardKey.arrowUp):
const DirectionalFocusIntent(TraversalDirection.up),
},
child: DemoPage(),
),
);
}
}
class DemoPage extends StatelessWidget {
final _fifthFocusNode = FocusNode();
DemoPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Focus Traversal Bug Demo'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
for (var i = 0; i < 10; i++)
Padding(
padding: const EdgeInsets.all(5.0),
child: ElevatedButton(
focusNode: i == 4 ? _fifthFocusNode : null,
autofocus: i == 4,
onPressed: () => _fifthFocusNode.requestFocus(),
child: Text('Button ${i+1}'),
),
),
],
),
),
);
}
}- Run above code using Flutter Web (Also reproducible on mobile emulator or with keyboard connected)
- See that Button 5 is focused
- Press 3x the arrow down key --> Now Button 8 is focused
- Press enter --> The focus jumps to Button 5 again
- Press the arrow up key
Expected results: When going up from Button 5, Button 4 should get focused
Actual results: Button 7 gets focused
screencast-2021-07-06_08.36.51.mp4
Flutter Doctor
[✓] Flutter (Channel master, 2.3.0-17.0.pre.414, on Fedora 33 (Workstation Edition) 5.12.11-200.fc33.x86_64, locale de_DE.UTF-8)
• Flutter version 2.3.0-17.0.pre.414 at /home/marcus/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 757c3add14 (vor 2 Wochen), 2021-06-20 22:29:02 -0400
• Engine revision 9520bb15b3
• Dart version 2.14.0 (build 2.14.0-228.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /home/marcus/Android/Sdk
• Platform android-30, build-tools 30.0.3
• Java binary at: /home/marcus/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• Chrome at google-chrome
[✓] Android Studio (version 4.1)
• Android Studio at /home/marcus/android-studio
• Flutter plugin version 54.1.1
• Dart plugin version 201.9335
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
[✓] VS Code (version 1.57.1)
• VS Code at /usr/share/code
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected device (1 available)
• Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.114
• No issues found!
Reacted by Fré Dumazy
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work listfound in release: 2.2Found to occur in 2.2Found to occur in 2.2frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagesteam-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Activity
darshankawar commentedon Jul 6, 2021
I see the same behavior on latest stable.
flutter doctor -v
yjbanov commentedon Jul 8, 2021
/cc @gspencergoog
yjbanov commentedon Jul 8, 2021
Does this only happen on the web?
gspencergoog commentedon Jul 8, 2021
It appears to only happen on web, and (for me) only in Dartpad. I tried it on Linux and in Chrome (master branch). I could only get it to happen in Dartpad: I couldn't reproduce it in Chrome.
In Dartpad at least, it seems to get worse each time the app is re-run: the first run it skips every other one each time the arrow or tab is pressed, and it skips two the next time the app is re-run, and so on.
MarcusWichelmann commentedon Jul 9, 2021
@yjbanov No, this is reproducible on an Android Emulator, too, as well as on real devices, like an Android TV where navigation happens using the d-pad of the remote.
lol 😄 This looks like another issue. I have never seen this behaviour on any of my testing devices or emulators.
gspencergoog commentedon Jul 9, 2021
I can't reproduce this on the Android Emulator.
flutter doctor -v
[✓] Flutter (Channel master, 2.4.0-1.0.pre.164, on Debian GNU/Linux rodete 5.10.28-1rodete2-amd64, locale en_US.UTF-8) • Flutter version 2.4.0-1.0.pre.164 at /home/gspencer/code/flutter • Upstream repository [email protected]:gspencergoog/flutter.git • Framework revision cb17425df0 (86 minutes ago), 2021-07-09 17:06:08 -0400 • Engine revision 0156ecd2e5 • Dart version 2.14.0 (build 2.14.0-295.0.dev)[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
• Android SDK at /home/gspencer/Android/Sdk
• Platform android-30, build-tools 30.0.1
• ANDROID_HOME = /home/gspencer/Android/Sdk
• Java binary at: /opt/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Chrome - develop for the web
• Chrome at google-chrome
[✓] Linux toolchain - develop for Linux desktop
• Debian clang version 11.0.1-2
• cmake version 3.18.4
• ninja version 1.8.2
• pkg-config version 0.29.2
[✓] VS Code (version 1.58.0)
• VS Code at /usr/share/code
• Flutter extension version 3.24.0
[✓] Connected device (3 available)
• Android SDK built for x86 64 (mobile) • emulator-5554 • android-x64 • Android 9 (API 28) (emulator)
• Linux (desktop) • linux • linux-x64 • Debian GNU/Linux rodete 5.10.28-1rodete2-amd64
• Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.114
• No issues found!
9 remaining items
MarcusWichelmann commentedon Oct 13, 2021
Still reproducible with latest Flutter 2.5.2.
flutter-triage-bot commentedon Aug 7, 2023
This issue is missing a priority label. Please set a priority label when adding the
triaged-designlabel.bpjhe commentedon Apr 11, 2025
Stumbled upon this today on version 3.27.4. Makes dpad navigation with a TV remote rather frustrating. Implementing scroll to top and focusing first element in a GridView, when clicking back on the remote, causes the same behavior as video in original post. Scrolling far enough down so that the widget you are coming from is disposed when jumping to the start does not trigger this problem.
Clear cached directional focus history on a non-directional focus req…
github-actions commentedon Aug 5, 2026
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.