Unverified Commit 3c278518 authored by JBBx2016's avatar JBBx2016 Committed by GitHub

Fixes issue where navigating to new route breaks FocusNode of previou… (#92615)

parent 15d0a8be
......@@ -488,8 +488,8 @@ class _FocusState extends State<Focus> {
if (widget.skipTraversal != null) {
focusNode.skipTraversal = widget.skipTraversal;
}
if (widget.canRequestFocus != null) {
focusNode.canRequestFocus = widget.canRequestFocus;
if (widget._canRequestFocus != null) {
focusNode.canRequestFocus = widget._canRequestFocus!;
}
_couldRequestFocus = focusNode.canRequestFocus;
_descendantsWereFocusable = focusNode.descendantsAreFocusable;
......@@ -575,8 +575,8 @@ class _FocusState extends State<Focus> {
if (widget.skipTraversal != null) {
focusNode.skipTraversal = widget.skipTraversal;
}
if (widget.canRequestFocus != null) {
focusNode.canRequestFocus = widget.canRequestFocus;
if (widget._canRequestFocus != null) {
focusNode.canRequestFocus = widget._canRequestFocus!;
}
focusNode.descendantsAreFocusable = widget.descendantsAreFocusable;
}
......
......@@ -1925,5 +1925,36 @@ void main() {
final TestSemantics expectedSemantics = TestSemantics.root();
expect(semantics, hasSemantics(expectedSemantics));
});
// Regression test for https://github.com/flutter/flutter/issues/92693
testWidgets('Setting parent FocusScope.canRequestFocus to false, does not set descendant Focus._internalNode._canRequestFocus to false', (WidgetTester tester) async {
final FocusNode childFocusNode = FocusNode(debugLabel: 'node 1');
Widget buildFocusTree({required bool parentCanRequestFocus}) {
return FocusScope(
canRequestFocus: parentCanRequestFocus,
child: Column(
children: <Widget>[
Focus(
focusNode: childFocusNode,
child: Container(),
),
],
),
);
}
// childFocusNode.canRequestFocus is true when parent canRequestFocus is true
await tester.pumpWidget(buildFocusTree(parentCanRequestFocus: true));
expect(childFocusNode.canRequestFocus, isTrue);
// childFocusNode.canRequestFocus is false when parent canRequestFocus is false
await tester.pumpWidget(buildFocusTree(parentCanRequestFocus: false));
expect(childFocusNode.canRequestFocus, isFalse);
// childFocusNode.canRequestFocus is true again when parent canRequestFocus is changed back to true
await tester.pumpWidget(buildFocusTree(parentCanRequestFocus: true));
expect(childFocusNode.canRequestFocus, isTrue);
});
});
}
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