Commit 8b09a532 authored by Erick (CptBlackPixel)'s avatar Erick (CptBlackPixel) Committed by Greg Spencer

Fixing focus traversal when the node options are empty (#43238)

Fixes directional focus traversal when there are no available nodes to traverse to.
parent d0d8e6ed
......@@ -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);
});
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment