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:
Erick (CptBlackPixel) 2019-10-30 18:54:29 -03:00 committed by Greg Spencer
parent d0d8e6edcb
commit 8b09a53252
2 changed files with 24 additions and 1 deletions

View file

@ -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

View file

@ -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);
});
});
}