-
Notifications
You must be signed in to change notification settings - Fork 26.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Focus navigation doesn't take transform into account when computing bounds #55338
Comments
I ran Output
The code compiles fine for me. I don't know why DefaultFocusTraversal is missing(?) for you (what is the error?). It's a standard Flutter widget. For me it's imported via this path:
But I realized it has no effect anyway, so please try this. import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
Widget button(String t) => Padding(
padding: EdgeInsets.symmetric(horizontal: 2.0),
child: RaisedButton(color: Colors.green, child: Text(t), onPressed: () {}),
);
Widget triangle() => Column(children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [button('a'), button('b'), button('c')]),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [button('d'), button('e'), button('f')]),
]);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
triangle(),
Transform.scale(scale: 0.5, alignment: Alignment.topCenter, child: triangle()),
]),
),
);
}
} |
Hi @lynn Using Tab to switchUsing Up and down arrow keys to switch (here we can see focus direction scaled down widgets)Can you please confirm the issue is same as this? |
@TahaTesser yes, I think I can see the issue in your second GIF. To see it most clearly, try moving with the arrow keys like this around the small widgets:
Sometimes, it will jump from EDIT: Actually, it looks like there is an issue with Tab too? In your GIF, the order is different in the small widgets ( |
Yes, I think this is because the focus traversal code isn't taking the context's transform into account when building the geometry to decide which widget to visit next. |
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 |
Steps to Reproduce
flutter create bug
.lib/main.dart
with:Expected results
The focus moves the same way in both rectangles of buttons.
Actual results
Sometimes, focus moves diagonally in the scaled-down example, e.g from
e
⬈c
when I press the “right” D-pad button on my gamepad withe
focused. It should go to frome
⮕f
.Investigation
Adding logging to
DirectionalFocusTraversalPolicyMixin.inDirection
shows that this is because the scaled-down buttonFocusNode
s have arect
with width/height equal to the originals, i.e. measured in local coordinates rather than global coordinates.So,
c
is detected as being “in-band” ofe
when moving right, becausec
's rect extends too far down. Ifc
happens to be first in the in-band list, it will get selected rather thanf
.Suggested Fix
In
flutter/lib/src/widgets/focus_manager.dart
, transform the whole rectangle, rather than only transforming itstopLeft
point and leavingsize
untouched:flutter doctor
The text was updated successfully, but these errors were encountered: