diff --git a/dev/integration_tests/new_gallery/lib/studies/rally/home.dart b/dev/integration_tests/new_gallery/lib/studies/rally/home.dart index ba4a3306ddbb3..f4e40c55ba18b 100644 --- a/dev/integration_tests/new_gallery/lib/studies/rally/home.dart +++ b/dev/integration_tests/new_gallery/lib/studies/rally/home.dart @@ -221,7 +221,7 @@ class _RallyTabBar extends StatelessWidget { @override Widget build(BuildContext context) { return FocusTraversalOrder( - order: const NumericFocusOrder(0), + order: const .numeric(0), child: TabBar( // Setting isScrollable to true prevents the tabs from being // wrapped in [Expanded] widgets, which allows for more diff --git a/dev/integration_tests/new_gallery/lib/studies/rally/tabs/overview.dart b/dev/integration_tests/new_gallery/lib/studies/rally/tabs/overview.dart index c811e9a09c1bb..a892df6b52dee 100644 --- a/dev/integration_tests/new_gallery/lib/studies/rally/tabs/overview.dart +++ b/dev/integration_tests/new_gallery/lib/studies/rally/tabs/overview.dart @@ -237,7 +237,7 @@ class _FinancialView extends StatelessWidget { Widget build(BuildContext context) { final ThemeData theme = Theme.of(context); return FocusTraversalOrder( - order: NumericFocusOrder(order!), + order: .numeric(order!), child: ColoredBox( color: RallyColors.cardBackground, child: Column( diff --git a/examples/api/lib/widgets/focus_traversal/focus_traversal_group.0.dart b/examples/api/lib/widgets/focus_traversal/focus_traversal_group.0.dart index 2b8d871d85503..0571239db3c18 100644 --- a/examples/api/lib/widgets/focus_traversal/focus_traversal_group.0.dart +++ b/examples/api/lib/widgets/focus_traversal/focus_traversal_group.0.dart @@ -43,10 +43,7 @@ class _OrderedButtonState extends State> { @override void initState() { super.initState(); - focusNode = FocusNode( - debugLabel: widget.name, - canRequestFocus: widget.canRequestFocus, - ); + focusNode = FocusNode(debugLabel: widget.name, canRequestFocus: widget.canRequestFocus); } @override @@ -70,8 +67,8 @@ class _OrderedButtonState extends State> { @override Widget build(BuildContext context) { final FocusOrder order = switch (widget.order) { - final num number => NumericFocusOrder(number.toDouble()), - final Object? object => LexicalFocusOrder(object.toString()), + final num number => .numeric(number.toDouble()), + final Object? object => .lexical(object.toString()), }; return FocusTraversalOrder( @@ -85,19 +82,13 @@ class _OrderedButtonState extends State> { overlayColor: WidgetStateProperty.fromMap( // If neither of these states is active, the property will // resolve to null, deferring to the default overlay color. - { - WidgetState.focused: Colors.red, - WidgetState.hovered: Colors.blue, - }, + {.focused: Colors.red, .hovered: Colors.blue}, ), foregroundColor: WidgetStateProperty.fromMap( // "WidgetState.focused | WidgetState.hovered" could be used // instead of separate map keys, but this setup allows setting // the button style to a constant value for improved efficiency. - { - WidgetState.focused: Colors.white, - WidgetState.hovered: Colors.white, - }, + {.focused: Colors.white, .hovered: Colors.white}, ), ), onPressed: () => _handleOnPressed(), @@ -141,13 +132,8 @@ class FocusTraversalGroupExample extends StatelessWidget { mainAxisAlignment: .center, children: List.generate(3, (int index) { // Order as "C" "B", "A". - final String order = String.fromCharCode( - 'A'.codeUnitAt(0) + (2 - index), - ); - return OrderedButton( - name: 'String: $order', - order: order, - ); + final String order = String.fromCharCode('A'.codeUnitAt(0) + (2 - index)); + return OrderedButton(name: 'String: $order', order: order); }), ), ), @@ -162,10 +148,7 @@ class FocusTraversalGroupExample extends StatelessWidget { child: Row( mainAxisAlignment: .center, children: List.generate(3, (int index) { - return OrderedButton( - name: 'ignored num: ${3 - index}', - order: 3 - index, - ); + return OrderedButton(name: 'ignored num: ${3 - index}', order: 3 - index); }), ), ), diff --git a/examples/api/lib/widgets/focus_traversal/ordered_traversal_policy.0.dart b/examples/api/lib/widgets/focus_traversal/ordered_traversal_policy.0.dart index bc07cf2a382e6..cec083faa4478 100644 --- a/examples/api/lib/widgets/focus_traversal/ordered_traversal_policy.0.dart +++ b/examples/api/lib/widgets/focus_traversal/ordered_traversal_policy.0.dart @@ -23,12 +23,7 @@ class OrderedTraversalPolicyExampleApp extends StatelessWidget { } class DemoButton extends StatelessWidget { - const DemoButton({ - super.key, - required this.name, - this.autofocus = false, - required this.order, - }); + const DemoButton({super.key, required this.name, this.autofocus = false, required this.order}); final String name; final bool autofocus; @@ -42,12 +37,8 @@ class DemoButton extends StatelessWidget { @override Widget build(BuildContext context) { return FocusTraversalOrder( - order: NumericFocusOrder(order), - child: TextButton( - autofocus: autofocus, - onPressed: () => _handleOnPressed(), - child: Text(name), - ), + order: .numeric(order), + child: TextButton(autofocus: autofocus, onPressed: () => _handleOnPressed(), child: Text(name)), ); } } diff --git a/packages/flutter/lib/src/widgets/focus_traversal.dart b/packages/flutter/lib/src/widgets/focus_traversal.dart index e54eb5fbcd3b8..5e4458f9124ee 100644 --- a/packages/flutter/lib/src/widgets/focus_traversal.dart +++ b/packages/flutter/lib/src/widgets/focus_traversal.dart @@ -1371,8 +1371,7 @@ mixin DirectionalFocusTraversalPolicyMixin on FocusTraversalPolicy { final FocusScopeNode nearestScope = currentNode.nearestScope!; final FocusNode? focusedChild = nearestScope.focusedChild; if (focusedChild == null) { - final FocusNode firstFocus = - findFirstFocusInDirection(currentNode, direction) ?? currentNode; + final FocusNode firstFocus = findFirstFocusInDirection(currentNode, direction) ?? currentNode; switch (direction) { case TraversalDirection.up: case TraversalDirection.left: @@ -1795,6 +1794,12 @@ abstract class FocusOrder with Diagnosticable implements Comparable /// const constructors so that they can be used in const expressions. const FocusOrder(); + /// Creates a [LexicalFocusOrder] that describes its order in lexical order. + const factory FocusOrder.lexical(String order) = LexicalFocusOrder; + + /// Creates a [NumericFocusOrder] that describes its order numerically. + const factory FocusOrder.numeric(double order) = NumericFocusOrder; + /// Compares this object to another [Comparable]. /// /// When overriding [FocusOrder], implement [doCompare] instead of this diff --git a/packages/flutter/test/widgets/focus_traversal_test.dart b/packages/flutter/test/widgets/focus_traversal_test.dart index 0d5697b8e571c..dc84864a57dc3 100644 --- a/packages/flutter/test/widgets/focus_traversal_test.dart +++ b/packages/flutter/test/widgets/focus_traversal_test.dart @@ -1196,11 +1196,11 @@ void main() { child: Column( children: [ FocusTraversalOrder( - order: const NumericFocusOrder(2), + order: const .numeric(2), child: Focus(child: SizedBox(key: key1, width: 100, height: 100)), ), FocusTraversalOrder( - order: const NumericFocusOrder(1), + order: const .numeric(1), child: Focus(child: SizedBox(key: key2, width: 100, height: 100)), ), ], @@ -1299,7 +1299,7 @@ void main() { children: List.generate( nodeCount, (int index) => FocusTraversalOrder( - order: NumericFocusOrder(nodeCount - index.toDouble()), + order: .numeric(nodeCount - index.toDouble()), child: Focus( focusNode: nodes[index], child: const SizedBox(width: 10, height: 10), @@ -1357,7 +1357,7 @@ void main() { children: List.generate( nodeCount, (int index) => FocusTraversalOrder( - order: LexicalFocusOrder(keys[index]), + order: .lexical(keys[index]), child: Focus( focusNode: nodes[index], child: const SizedBox(width: 10, height: 10), @@ -1413,27 +1413,27 @@ void main() { child: Row( children: [ FocusTraversalOrder( - order: const NumericFocusOrder(0), + order: const .numeric(0), child: FocusTraversalGroup( policy: WidgetOrderTraversalPolicy(), child: Row( children: [ FocusTraversalOrder( - order: const NumericFocusOrder(9), + order: const .numeric(9), child: Focus( focusNode: nodes[9], child: const SizedBox(width: 10, height: 10), ), ), FocusTraversalOrder( - order: const NumericFocusOrder(8), + order: const .numeric(8), child: Focus( focusNode: nodes[8], child: const SizedBox(width: 10, height: 10), ), ), FocusTraversalOrder( - order: const NumericFocusOrder(7), + order: const .numeric(7), child: Focus( focusNode: nodes[7], child: const SizedBox(width: 10, height: 10), @@ -1444,27 +1444,27 @@ void main() { ), ), FocusTraversalOrder( - order: const NumericFocusOrder(1), + order: const .numeric(1), child: FocusTraversalGroup( policy: OrderedTraversalPolicy(secondary: WidgetOrderTraversalPolicy()), child: Row( children: [ FocusTraversalOrder( - order: const NumericFocusOrder(4), + order: const .numeric(4), child: Focus( focusNode: nodes[4], child: const SizedBox(width: 10, height: 10), ), ), FocusTraversalOrder( - order: const NumericFocusOrder(5), + order: const .numeric(5), child: Focus( focusNode: nodes[5], child: const SizedBox(width: 10, height: 10), ), ), FocusTraversalOrder( - order: const NumericFocusOrder(6), + order: const .numeric(6), child: Focus( focusNode: nodes[6], child: const SizedBox(width: 10, height: 10), @@ -1475,34 +1475,34 @@ void main() { ), ), FocusTraversalOrder( - order: const NumericFocusOrder(2), + order: const .numeric(2), child: FocusTraversalGroup( policy: OrderedTraversalPolicy(secondary: WidgetOrderTraversalPolicy()), child: Row( children: [ FocusTraversalOrder( - order: const LexicalFocusOrder('D'), + order: const .lexical('D'), child: Focus( focusNode: nodes[3], child: const SizedBox(width: 10, height: 10), ), ), FocusTraversalOrder( - order: const LexicalFocusOrder('C'), + order: const .lexical('C'), child: Focus( focusNode: nodes[2], child: const SizedBox(width: 10, height: 10), ), ), FocusTraversalOrder( - order: const LexicalFocusOrder('B'), + order: const .lexical('B'), child: Focus( focusNode: nodes[1], child: const SizedBox(width: 10, height: 10), ), ), FocusTraversalOrder( - order: const LexicalFocusOrder('A'), + order: const .lexical('A'), child: Focus( focusNode: nodes[0], child: const SizedBox(width: 10, height: 10), @@ -1548,7 +1548,7 @@ void main() { child: Builder( builder: (BuildContext context) { return FocusTraversalOrder( - order: const NumericFocusOrder(0), + order: const .numeric(0), child: TestButton( key: key1, focusNode: testNode1, @@ -1564,7 +1564,7 @@ void main() { ) { return Center( child: FocusTraversalOrder( - order: const NumericFocusOrder(0), + order: const .numeric(0), child: TestButton( key: key2, focusNode: testNode2, @@ -3108,169 +3108,165 @@ void main() { variant: KeySimulatorTransitModeVariant.all(), ); - testWidgets( - 'Arrow focus traversal actions can be re-enabled for text fields.', - (WidgetTester tester) async { - final GlobalKey upperLeftKey = GlobalKey(debugLabel: 'upperLeftKey'); - final GlobalKey upperRightKey = GlobalKey(debugLabel: 'upperRightKey'); - final GlobalKey lowerLeftKey = GlobalKey(debugLabel: 'lowerLeftKey'); - final GlobalKey lowerRightKey = GlobalKey(debugLabel: 'lowerRightKey'); + testWidgets('Arrow focus traversal actions can be re-enabled for text fields.', ( + WidgetTester tester, + ) async { + final GlobalKey upperLeftKey = GlobalKey(debugLabel: 'upperLeftKey'); + final GlobalKey upperRightKey = GlobalKey(debugLabel: 'upperRightKey'); + final GlobalKey lowerLeftKey = GlobalKey(debugLabel: 'lowerLeftKey'); + final GlobalKey lowerRightKey = GlobalKey(debugLabel: 'lowerRightKey'); - final controller1 = TextEditingController(); - addTearDown(controller1.dispose); - final controller2 = TextEditingController(); - addTearDown(controller2.dispose); - final controller3 = TextEditingController(); - addTearDown(controller3.dispose); - final controller4 = TextEditingController(); - addTearDown(controller4.dispose); - - final focusNodeUpperLeft = FocusNode(debugLabel: 'upperLeft'); - addTearDown(focusNodeUpperLeft.dispose); - final focusNodeUpperRight = FocusNode(debugLabel: 'upperRight'); - addTearDown(focusNodeUpperRight.dispose); - final focusNodeLowerLeft = FocusNode(debugLabel: 'lowerLeft'); - addTearDown(focusNodeLowerLeft.dispose); - final focusNodeLowerRight = FocusNode(debugLabel: 'lowerRight'); - addTearDown(focusNodeLowerRight.dispose); - - Widget generateTestWidgets(bool ignoreTextFields) { - final shortcuts = { - const SingleActivator(LogicalKeyboardKey.arrowLeft): DirectionalFocusIntent( - TraversalDirection.left, - ignoreTextFields: ignoreTextFields, - ), - const SingleActivator(LogicalKeyboardKey.arrowRight): DirectionalFocusIntent( - TraversalDirection.right, - ignoreTextFields: ignoreTextFields, - ), - const SingleActivator(LogicalKeyboardKey.arrowDown): DirectionalFocusIntent( - TraversalDirection.down, - ignoreTextFields: ignoreTextFields, - ), - const SingleActivator(LogicalKeyboardKey.arrowUp): DirectionalFocusIntent( - TraversalDirection.up, - ignoreTextFields: ignoreTextFields, - ), - }; + final controller1 = TextEditingController(); + addTearDown(controller1.dispose); + final controller2 = TextEditingController(); + addTearDown(controller2.dispose); + final controller3 = TextEditingController(); + addTearDown(controller3.dispose); + final controller4 = TextEditingController(); + addTearDown(controller4.dispose); + + final focusNodeUpperLeft = FocusNode(debugLabel: 'upperLeft'); + addTearDown(focusNodeUpperLeft.dispose); + final focusNodeUpperRight = FocusNode(debugLabel: 'upperRight'); + addTearDown(focusNodeUpperRight.dispose); + final focusNodeLowerLeft = FocusNode(debugLabel: 'lowerLeft'); + addTearDown(focusNodeLowerLeft.dispose); + final focusNodeLowerRight = FocusNode(debugLabel: 'lowerRight'); + addTearDown(focusNodeLowerRight.dispose); + + Widget generateTestWidgets(bool ignoreTextFields) { + final shortcuts = { + const SingleActivator(LogicalKeyboardKey.arrowLeft): DirectionalFocusIntent( + TraversalDirection.left, + ignoreTextFields: ignoreTextFields, + ), + const SingleActivator(LogicalKeyboardKey.arrowRight): DirectionalFocusIntent( + TraversalDirection.right, + ignoreTextFields: ignoreTextFields, + ), + const SingleActivator(LogicalKeyboardKey.arrowDown): DirectionalFocusIntent( + TraversalDirection.down, + ignoreTextFields: ignoreTextFields, + ), + const SingleActivator(LogicalKeyboardKey.arrowUp): DirectionalFocusIntent( + TraversalDirection.up, + ignoreTextFields: ignoreTextFields, + ), + }; - return TestWidgetsApp( - home: Shortcuts( - shortcuts: shortcuts, - child: FocusScope( - debugLabel: 'scope', - child: Column( - children: [ - Row( - children: [ - SizedBox.square( - dimension: 100.0, - child: EditableText( - autofocus: true, - key: upperLeftKey, - controller: controller1, - focusNode: focusNodeUpperLeft, - cursorColor: const Color(0xffffffff), - backgroundCursorColor: const Color(0xff808080), - style: const TextStyle(), - ), + return TestWidgetsApp( + home: Shortcuts( + shortcuts: shortcuts, + child: FocusScope( + debugLabel: 'scope', + child: Column( + children: [ + Row( + children: [ + SizedBox.square( + dimension: 100.0, + child: EditableText( + autofocus: true, + key: upperLeftKey, + controller: controller1, + focusNode: focusNodeUpperLeft, + cursorColor: const Color(0xffffffff), + backgroundCursorColor: const Color(0xff808080), + style: const TextStyle(), ), - SizedBox.square( - dimension: 100.0, - child: EditableText( - key: upperRightKey, - controller: controller2, - focusNode: focusNodeUpperRight, - cursorColor: const Color(0xffffffff), - backgroundCursorColor: const Color(0xff808080), - style: const TextStyle(), - ), + ), + SizedBox.square( + dimension: 100.0, + child: EditableText( + key: upperRightKey, + controller: controller2, + focusNode: focusNodeUpperRight, + cursorColor: const Color(0xffffffff), + backgroundCursorColor: const Color(0xff808080), + style: const TextStyle(), ), - ], - ), - Row( - children: [ - SizedBox.square( - dimension: 100.0, - child: EditableText( - key: lowerLeftKey, - controller: controller3, - focusNode: focusNodeLowerLeft, - cursorColor: const Color(0xffffffff), - backgroundCursorColor: const Color(0xff808080), - style: const TextStyle(), - ), + ), + ], + ), + Row( + children: [ + SizedBox.square( + dimension: 100.0, + child: EditableText( + key: lowerLeftKey, + controller: controller3, + focusNode: focusNodeLowerLeft, + cursorColor: const Color(0xffffffff), + backgroundCursorColor: const Color(0xff808080), + style: const TextStyle(), ), - SizedBox.square( - dimension: 100.0, - child: EditableText( - key: lowerRightKey, - controller: controller4, - focusNode: focusNodeLowerRight, - cursorColor: const Color(0xffffffff), - backgroundCursorColor: const Color(0xff808080), - style: const TextStyle(), - ), + ), + SizedBox.square( + dimension: 100.0, + child: EditableText( + key: lowerRightKey, + controller: controller4, + focusNode: focusNodeLowerRight, + cursorColor: const Color(0xffffffff), + backgroundCursorColor: const Color(0xff808080), + style: const TextStyle(), ), - ], - ), - ], - ), + ), + ], + ), + ], ), ), - ); - } - - await tester.pumpWidget(generateTestWidgets(false)); - - expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue); - await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); - expect(focusNodeUpperRight.hasPrimaryFocus, isTrue); - await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); - expect(focusNodeLowerRight.hasPrimaryFocus, isTrue); - await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft); - expect(focusNodeLowerLeft.hasPrimaryFocus, isTrue); - await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp); - expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue); - - await tester.pumpWidget(generateTestWidgets(true)); - - expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue); - await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); - expect(focusNodeUpperRight.hasPrimaryFocus, isFalse); - expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue); - await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); - expect(focusNodeLowerRight.hasPrimaryFocus, isFalse); - expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue); - await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft); - expect(focusNodeLowerLeft.hasPrimaryFocus, isFalse); - expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue); - await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp); - expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue); - }, - variant: KeySimulatorTransitModeVariant.all(), - ); + ), + ); + } - testWidgets( - 'Focus traversal does not break when no focusable is available on a WidgetsApp', - (WidgetTester tester) async { - final events = []; + await tester.pumpWidget(generateTestWidgets(false)); + + expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue); + await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); + expect(focusNodeUpperRight.hasPrimaryFocus, isTrue); + await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); + expect(focusNodeLowerRight.hasPrimaryFocus, isTrue); + await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft); + expect(focusNodeLowerLeft.hasPrimaryFocus, isTrue); + await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp); + expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue); + + await tester.pumpWidget(generateTestWidgets(true)); + + expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue); + await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); + expect(focusNodeUpperRight.hasPrimaryFocus, isFalse); + expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue); + await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown); + expect(focusNodeLowerRight.hasPrimaryFocus, isFalse); + expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue); + await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft); + expect(focusNodeLowerLeft.hasPrimaryFocus, isFalse); + expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue); + await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp); + expect(focusNodeUpperLeft.hasPrimaryFocus, isTrue); + }, variant: KeySimulatorTransitModeVariant.all()); + + testWidgets('Focus traversal does not break when no focusable is available on a WidgetsApp', ( + WidgetTester tester, + ) async { + final events = []; - await tester.pumpWidget(TestWidgetsApp(home: Container())); + await tester.pumpWidget(TestWidgetsApp(home: Container())); - HardwareKeyboard.instance.addHandler((KeyEvent event) { - events.add(event); - return true; - }); + HardwareKeyboard.instance.addHandler((KeyEvent event) { + events.add(event); + return true; + }); - await tester.idle(); - await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); - await tester.idle(); + await tester.idle(); + await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); + await tester.idle(); - expect(events.length, 2); - }, - variant: KeySimulatorTransitModeVariant.all(), - ); + expect(events.length, 2); + }, variant: KeySimulatorTransitModeVariant.all()); testWidgets('Focus traversal does not throw when no focusable is available in a group', ( WidgetTester tester, @@ -3286,26 +3282,24 @@ void main() { expect(primaryFocus, equals(initialFocus)); }); - testWidgets( - 'Focus traversal does not break when no focusable is available on a WidgetsApp', - (WidgetTester tester) async { - final events = []; + testWidgets('Focus traversal does not break when no focusable is available on a WidgetsApp', ( + WidgetTester tester, + ) async { + final events = []; - await tester.pumpWidget(const TestWidgetsApp(home: Placeholder())); + await tester.pumpWidget(const TestWidgetsApp(home: Placeholder())); - HardwareKeyboard.instance.addHandler((KeyEvent event) { - events.add(event); - return true; - }); + HardwareKeyboard.instance.addHandler((KeyEvent event) { + events.add(event); + return true; + }); - await tester.idle(); - await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); - await tester.idle(); + await tester.idle(); + await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight); + await tester.idle(); - expect(events.length, 2); - }, - variant: KeySimulatorTransitModeVariant.all(), - ); + expect(events.length, 2); + }, variant: KeySimulatorTransitModeVariant.all()); testWidgets('Custom requestFocusCallback gets called on focusInDirection up/down/left/right.', ( WidgetTester tester, @@ -3490,7 +3484,10 @@ void main() { // FocusScope above. parentNode reparents it to the root scope. child: FocusTraversalGroup( parentNode: FocusManager.instance.rootScope, - child: Focus(focusNode: childNode, child: SizedBox(key: key)), + child: Focus( + focusNode: childNode, + child: SizedBox(key: key), + ), ), ), ), diff --git a/packages/flutter/test/widgets/framework_test.dart b/packages/flutter/test/widgets/framework_test.dart index 000097ab1f519..7a2b17226a064 100644 --- a/packages/flutter/test/widgets/framework_test.dart +++ b/packages/flutter/test/widgets/framework_test.dart @@ -1714,7 +1714,7 @@ void main() { final element = TestRenderObjectElement(); final focusTraversalOrder = _TestInheritedElement( - const FocusTraversalOrder(order: LexicalFocusOrder(''), child: Placeholder()), + const FocusTraversalOrder(order: .lexical(''), child: Placeholder()), ); final directionality = _TestInheritedElement( const Directionality(textDirection: TextDirection.ltr, child: Placeholder()),