mirror of
https://github.com/flutter/flutter
synced 2024-10-13 11:42:54 +00:00
Fixing focus traversal when the node options are empty (#43238)
Fixes directional focus traversal when there are no available nodes to traverse to.
This commit is contained in:
parent
d0d8e6edcb
commit
8b09a53252
|
@ -249,7 +249,11 @@ mixin DirectionalFocusTraversalPolicyMixin on FocusTraversalPolicy {
|
|||
}
|
||||
}
|
||||
});
|
||||
return sorted.first;
|
||||
|
||||
if (sorted.isNotEmpty)
|
||||
return sorted.first;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Sorts nodes from left to right horizontally, and removes nodes that are
|
||||
|
|
|
@ -1127,6 +1127,25 @@ void main() {
|
|||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
|
||||
expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue);
|
||||
});
|
||||
testWidgets('Focus traversal does not break when no focusable is available on a MaterialApp', (WidgetTester tester) async {
|
||||
final List<RawKeyEvent> events = <RawKeyEvent>[];
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Container()
|
||||
)
|
||||
);
|
||||
|
||||
RawKeyboard.instance.addListener((RawKeyEvent event) {
|
||||
events.add(event);
|
||||
});
|
||||
|
||||
await tester.idle();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.idle();
|
||||
|
||||
expect(events.length, 2);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue