From cb906179117a0d585bd79e43ac0e5568ef488ca6 Mon Sep 17 00:00:00 2001 From: Todd Volkert Date: Mon, 3 Jun 2019 17:24:56 -0700 Subject: [PATCH] Revert "ModalRoute resumes previous focus on didPopNext (#33152)" (#33815) This reverts commit 0f2254a5c334b2435167083b48e681f4fb18acd4. --- packages/flutter/lib/src/widgets/routes.dart | 11 ----- .../test/material/text_field_focus_test.dart | 5 ++ .../flutter/test/widgets/routes_test.dart | 47 ------------------- 3 files changed, 5 insertions(+), 58 deletions(-) diff --git a/packages/flutter/lib/src/widgets/routes.dart b/packages/flutter/lib/src/widgets/routes.dart index e7dcd7f2a2..d2fbaa7168 100644 --- a/packages/flutter/lib/src/widgets/routes.dart +++ b/packages/flutter/lib/src/widgets/routes.dart @@ -1086,17 +1086,6 @@ abstract class ModalRoute extends TransitionRoute with LocalHistoryRoute nextRoute) { - super.didPopNext(nextRoute); - // When the route on top of this route is popped, resume focus onto the - // widget that received the last focus. - final _ModalScopeState modalScopeState = _scopeKey.currentState; - if (modalScopeState != null) { - modalScopeState.focusScopeNode.requestFocus(); - } - } - /// Enables this route to veto attempts by the user to dismiss it. /// /// This callback is typically added using a [WillPopScope] widget. That diff --git a/packages/flutter/test/material/text_field_focus_test.dart b/packages/flutter/test/material/text_field_focus_test.dart index b2711abcec..39a6a02a88 100644 --- a/packages/flutter/test/material/text_field_focus_test.dart +++ b/packages/flutter/test/material/text_field_focus_test.dart @@ -40,6 +40,11 @@ void main() { Navigator.of(tester.element(find.text('Dialog'))).pop(); await tester.pump(); + expect(tester.testTextInput.isVisible, isFalse); + + await tester.tap(find.byType(TextField)); + await tester.idle(); + expect(tester.testTextInput.isVisible, isTrue); await tester.pumpWidget(Container()); diff --git a/packages/flutter/test/widgets/routes_test.dart b/packages/flutter/test/widgets/routes_test.dart index 4d5492ec85..0ffbbf720d 100644 --- a/packages/flutter/test/widgets/routes_test.dart +++ b/packages/flutter/test/widgets/routes_test.dart @@ -8,7 +8,6 @@ import 'package:flutter/foundation.dart'; import 'package:mockito/mockito.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter/widgets.dart'; -import 'package:flutter/material.dart'; final List results = []; @@ -504,52 +503,6 @@ void main() { verifyNoMoreInteractions(pageRouteAware); }); }); - - group('ModalRoute', () { - testWidgets('should resume focus when the next route is popped', (WidgetTester tester) async { - // TODO(tongmu): It's currently using PageRoute (from MaterialApp) - // instead of ModalRoute, which might leave a risk but avoids building - // everything from scratch by using the existing setup by MaterialApp and - // TextField as a focusable widget. We might want to write a better test. - - final FocusNode node = FocusNode(); - BuildContext pageContext; - final Widget widget = MaterialApp( - theme: ThemeData(), - home: Material( - child: Builder( - builder: (BuildContext context) { - pageContext = context; - return Column( - children: [ - const TextField(), - TextField(focusNode: node), - ], - ); - } - ), - ), - ); - - await tester.pumpWidget(widget); - expect(node.hasFocus, false); - - node.requestFocus(); - await tester.pumpAndSettle(); - expect(node.hasFocus, true); - - showDialog( - context: pageContext, - builder: (BuildContext _) => const Center(), - ); - await tester.pumpAndSettle(); - expect(node.hasFocus, false); - - Navigator.of(pageContext).pop(); - await tester.pumpAndSettle(); - expect(node.hasFocus, true); - }); - }); } class MockPageRoute extends Mock implements PageRoute { }