From 79f13c36258380408eb1a1738178b964be3bf7f3 Mon Sep 17 00:00:00 2001 From: xster Date: Thu, 19 Oct 2017 17:34:39 -0700 Subject: [PATCH] Revert "Add a way to get the furthest Navigator" (#12608) * Revert "BoxDecoration.borderRadius and RoundedRectangleBorder.borderRadius RTL (#12603)" This reverts commit 07908916003fdc9078275b75eee40090f36b1cef. * Revert "Copy snapshot file into assets (#12523)" This reverts commit f6135107bcba92f02df6572d1a8be5e93863e6f6. * Revert "Add a rootNavigator option to Navigator.of (#12580)" This reverts commit 822084b235eab2f899a89706c622c08512295a4b. --- .../flutter/lib/src/cupertino/dialog.dart | 3 - packages/flutter/lib/src/material/dialog.dart | 2 +- .../flutter/lib/src/widgets/framework.dart | 24 ------- .../flutter/lib/src/widgets/navigator.dart | 13 +--- .../flutter/test/widgets/navigator_test.dart | 67 ------------------- 5 files changed, 3 insertions(+), 106 deletions(-) diff --git a/packages/flutter/lib/src/cupertino/dialog.dart b/packages/flutter/lib/src/cupertino/dialog.dart index 2c8a07711d..6e4a9fd7ff 100644 --- a/packages/flutter/lib/src/cupertino/dialog.dart +++ b/packages/flutter/lib/src/cupertino/dialog.dart @@ -53,9 +53,6 @@ const BoxDecoration _kCupertinoDialogBackFill = const BoxDecoration( /// dialog. Rather than using this widget directly, consider using /// [CupertinoAlertDialog], which implement a specific kind of dialog. /// -/// Push with `Navigator.of(..., rootNavigator: true)` when using with -/// [CupertinoTabScaffold] to ensure that the dialog appears above the tabs. -/// /// See also: /// /// * [CupertinoAlertDialog], which is a dialog with title, contents, and diff --git a/packages/flutter/lib/src/material/dialog.dart b/packages/flutter/lib/src/material/dialog.dart index 97190f3bfc..5221ff649a 100644 --- a/packages/flutter/lib/src/material/dialog.dart +++ b/packages/flutter/lib/src/material/dialog.dart @@ -461,7 +461,7 @@ Future showDialog({ bool barrierDismissible: true, @required Widget child, }) { - return Navigator.of(context, rootNavigator: true).push(new _DialogRoute( + return Navigator.push(context, new _DialogRoute( child: child, theme: Theme.of(context, shadowThemeOnly: true), barrierDismissible: barrierDismissible, diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 043d89b778..bc01d99c54 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -2003,17 +2003,6 @@ abstract class BuildContext { /// ``` State ancestorStateOfType(TypeMatcher matcher); - /// Returns the [State] object of the furthest ancestor [StatefulWidget] widget - /// that matches the given [TypeMatcher]. - /// - /// Functions the same way as [ancestorStateOfType] but keeps visiting subsequent - /// ancestors until there are none of the type matching [TypeMatcher] remaining. - /// Then returns the last one found. - /// - /// This operation is O(N) as well though N is the entire widget tree rather than - /// a subtree. - State rootAncestorStateOfType(TypeMatcher matcher); - /// Returns the [RenderObject] object of the nearest ancestor [RenderObjectWidget] widget /// that matches the given [TypeMatcher]. /// @@ -3256,19 +3245,6 @@ abstract class Element extends DiagnosticableTree implements BuildContext { return statefulAncestor?.state; } - @override - State rootAncestorStateOfType(TypeMatcher matcher) { - assert(_debugCheckStateIsActiveForAncestorLoopkup()); - Element ancestor = _parent; - StatefulElement statefulAncestor; - while (ancestor != null) { - if (ancestor is StatefulElement && matcher.check(ancestor.state)) - statefulAncestor = ancestor; - ancestor = ancestor._parent; - } - return statefulAncestor?.state; - } - @override RenderObject ancestorRenderObjectOfType(TypeMatcher matcher) { assert(_debugCheckStateIsActiveForAncestorLoopkup()); diff --git a/packages/flutter/lib/src/widgets/navigator.dart b/packages/flutter/lib/src/widgets/navigator.dart index 09c5ccc400..6a171d2786 100644 --- a/packages/flutter/lib/src/widgets/navigator.dart +++ b/packages/flutter/lib/src/widgets/navigator.dart @@ -708,17 +708,8 @@ class Navigator extends StatefulWidget { /// ..pop() /// ..pushNamed('/settings'); /// ``` - /// - /// If `rootNavigator` is set to true, the state from the furthest instance of - /// this class is given instead. Useful for pushing contents above all subsequent - /// instances of [Navigator]. - static NavigatorState of( - BuildContext context, { - bool rootNavigator: false - }) { - final NavigatorState navigator = rootNavigator - ? context.rootAncestorStateOfType(const TypeMatcher()) - : context.ancestorStateOfType(const TypeMatcher()); + static NavigatorState of(BuildContext context) { + final NavigatorState navigator = context.ancestorStateOfType(const TypeMatcher()); assert(() { if (navigator == null) { throw new FlutterError( diff --git a/packages/flutter/test/widgets/navigator_test.dart b/packages/flutter/test/widgets/navigator_test.dart index ed8ac80e20..68849e2563 100644 --- a/packages/flutter/test/widgets/navigator_test.dart +++ b/packages/flutter/test/widgets/navigator_test.dart @@ -179,73 +179,6 @@ void main() { expect('$exception', startsWith('Navigator operation requested with a context')); }); - testWidgets('Navigator.of rootNavigator finds root Navigator', (WidgetTester tester) async { - await tester.pumpWidget(new MaterialApp( - home: new Material( - child: new Column( - children: [ - const SizedBox( - height: 300.0, - child: const Text('Root page'), - ), - new SizedBox( - height: 300.0, - child: new Navigator( - onGenerateRoute: (RouteSettings settings) { - if (settings.isInitialRoute) { - return new MaterialPageRoute( - builder: (BuildContext context) { - return new RaisedButton( - child: const Text('Next'), - onPressed: () { - Navigator.of(context).push( - new MaterialPageRoute( - builder: (BuildContext context) { - return new RaisedButton( - child: const Text('Inner page'), - onPressed: () { - Navigator.of(context, rootNavigator: true).push( - new MaterialPageRoute( - builder: (BuildContext context) { - return const Text('Dialog'); - } - ), - ); - }, - ); - } - ), - ); - }, - ); - }, - ); - } - }, - ), - ), - ], - ), - ), - )); - - await tester.tap(find.text('Next')); - await tester.pump(); - await tester.pump(const Duration(milliseconds: 300)); - - // Both elements are on screen. - expect(tester.getTopLeft(find.text('Root page')).dy, 0.0); - expect(tester.getTopLeft(find.text('Inner page')).dy, greaterThan(300.0)); - - await tester.tap(find.text('Inner page')); - await tester.pump(); - await tester.pump(const Duration(milliseconds: 300)); - - // Dialog is pushed to the whole page and is at the top of the screen, not - // inside the inner page. - expect(tester.getTopLeft(find.text('Dialog')).dy, 0.0); - }); - testWidgets('Gestures between push and build are ignored', (WidgetTester tester) async { final List log = []; final Map routes = {