Browse Source

Add transitioned page router creation function

Luke 8 years ago
parent
commit
3ebc12f7ff
1 changed files with 16 additions and 1 deletions
  1. 16 1
      lib/src/router.dart

+ 16 - 1
lib/src/router.dart

@@ -8,7 +8,22 @@ class Router {
   AppRoute notFoundRoute;
   AppRoute notFoundRoute;
 
 
   /// Creates a custom [Route] definition
   /// Creates a custom [Route] definition
-  void defineRoute<T extends Route<Null>>(String routePath, {@required RouteCreator creator}) {
+  void defineRoute(String routePath, {@required RouteCreator creator}) {
+    _routeTree.addRoute(new AppRoute(routePath, creator));
+  }
+
+  /// Creates a [PageRoute] definition for the passed [RouteHandler]. You can optionally provide a custom
+  /// transition builder for the route.
+  void defineRouteHandler(String routePath, {@required RouteHandler handler, RouteTransitionsBuilder transitionsBuilder,
+      Duration duration = const Duration(milliseconds: 250)})
+  {
+    RouteCreator creator = (RouteSettings routeSettings, Map<String, String> params) {
+      return new PageRouteBuilder(settings: routeSettings, transitionDuration: duration,
+          transitionsBuilder:  transitionsBuilder,
+          pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
+            return handler(params);
+          });
+    };
     _routeTree.addRoute(new AppRoute(routePath, creator));
     _routeTree.addRoute(new AppRoute(routePath, creator));
   }
   }