diff --git a/packages/flutter/lib/src/material/page.dart b/packages/flutter/lib/src/material/page.dart index acc404fdd8..e3bfb730b4 100644 --- a/packages/flutter/lib/src/material/page.dart +++ b/packages/flutter/lib/src/material/page.dart @@ -5,8 +5,6 @@ import 'package:flutter/animation.dart'; import 'package:flutter/widgets.dart'; -import 'colors.dart'; - class _MaterialPageTransition extends TransitionWithChild { _MaterialPageTransition({ Key key, @@ -52,7 +50,8 @@ class MaterialPageRoute extends PageRoute { final WidgetBuilder builder; Duration get transitionDuration => kMaterialPageRouteTransitionDuration; - Color get barrierColor => Colors.black54; + Color get barrierColor => null; + bool canTransitionFrom(TransitionRoute nextRoute) => false; Widget buildPage(BuildContext context) { Widget result = builder(context); diff --git a/packages/flutter/lib/src/widgets/routes.dart b/packages/flutter/lib/src/widgets/routes.dart index a727ac9139..1f2384a296 100644 --- a/packages/flutter/lib/src/widgets/routes.dart +++ b/packages/flutter/lib/src/widgets/routes.dart @@ -150,7 +150,7 @@ abstract class TransitionRoute extends OverlayRoute { final ProxyPerformance forwardPerformance = new ProxyPerformance(); void didPushNext(Route nextRoute) { - if (nextRoute is TransitionRoute) { + if (nextRoute is TransitionRoute && canTransitionTo(nextRoute) && nextRoute.canTransitionFrom(this)) { PerformanceView current = forwardPerformance.masterPerformance; if (current != null) { if (current is TrainHoppingPerformance) { @@ -177,6 +177,9 @@ abstract class TransitionRoute extends OverlayRoute { super.didPushNext(nextRoute); } + bool canTransitionTo(TransitionRoute nextRoute) => true; + bool canTransitionFrom(TransitionRoute nextRoute) => true; + Widget wrapTransition(BuildContext context, Widget child) { return buildForwardTransition( context, @@ -437,4 +440,6 @@ abstract class PageRoute extends ModalRoute { }) : super(completer: completer, settings: settings); bool get opaque => true; bool get barrierDismissable => false; + bool canTransitionTo(TransitionRoute nextRoute) => nextRoute is PageRoute; + bool canTransitionFrom(TransitionRoute nextRoute) => nextRoute is PageRoute; } diff --git a/packages/unit/test/widget/page_forward_transitions_test.dart b/packages/unit/test/widget/page_forward_transitions_test.dart index 1d5d2448fa..92c18f79e2 100644 --- a/packages/unit/test/widget/page_forward_transitions_test.dart +++ b/packages/unit/test/widget/page_forward_transitions_test.dart @@ -27,6 +27,14 @@ class TestTransition extends TransitionComponent { } } +class TestRoute extends PageRoute { + TestRoute(this.child); + final Widget child; + Duration get transitionDuration => kMaterialPageRouteTransitionDuration; + Color get barrierColor => null; + Widget buildPage(BuildContext context) => child; +} + void main() { final Duration kTwoTenthsOfTheTransitionDuration = kMaterialPageRouteTransitionDuration * 0.2; final Duration kFourTenthsOfTheTransitionDuration = kMaterialPageRouteTransitionDuration * 0.4; @@ -57,30 +65,33 @@ void main() { tester.pumpWidget( new MaterialApp( - routes: { - '/': (RouteArguments args) { - return new Builder( - key: insideKey, - builder: (BuildContext context) { - PageRoute route = ModalRoute.of(context); - return new Column([ - new TestTransition( - childFirstHalf: new Text('A'), - childSecondHalf: new Text('B'), - performance: route.performance - ), - new TestTransition( - childFirstHalf: new Text('C'), - childSecondHalf: new Text('D'), - performance: route.forwardPerformance - ), - ]); - } - ); - }, - '/2': (RouteArguments args) => new Text('E'), - '/3': (RouteArguments args) => new Text('F'), - '/4': (RouteArguments args) => new Text('G'), + onGenerateRoute: (NamedRouteSettings settings) { + switch (settings.name) { + case '/': + return new TestRoute( + new Builder( + key: insideKey, + builder: (BuildContext context) { + PageRoute route = ModalRoute.of(context); + return new Column([ + new TestTransition( + childFirstHalf: new Text('A'), + childSecondHalf: new Text('B'), + performance: route.performance + ), + new TestTransition( + childFirstHalf: new Text('C'), + childSecondHalf: new Text('D'), + performance: route.forwardPerformance + ), + ]); + } + ) + ); + case '/2': return new TestRoute(new Text('E')); + case '/3': return new TestRoute(new Text('F')); + case '/4': return new TestRoute(new Text('G')); + } } ) );