|
@@ -13,16 +13,6 @@ import 'package:fluro/fluro.dart';
|
|
|
import 'package:fluro/src/common.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
-enum TransitionType {
|
|
|
- native,
|
|
|
- nativeModal,
|
|
|
- inFromLeft,
|
|
|
- inFromRight,
|
|
|
- inFromBottom,
|
|
|
- fadeIn,
|
|
|
- custom, // if using custom then you must also provide a transition
|
|
|
-}
|
|
|
-
|
|
|
class Router {
|
|
|
static final appRouter = new Router();
|
|
|
|
|
@@ -32,10 +22,11 @@ class Router {
|
|
|
/// Generic handler for when a route has not been defined
|
|
|
Handler notFoundHandler;
|
|
|
|
|
|
- /// Creates a [PageRoute] definition for the passed [RouteHandler]. You can optionally provide a custom
|
|
|
- /// transition builder for the route.
|
|
|
- void define(String routePath, {@required Handler handler}) {
|
|
|
- _routeTree.addRoute(new AppRoute(routePath, handler));
|
|
|
+ /// Creates a [PageRoute] definition for the passed [RouteHandler]. You can optionally provide a default transition type.
|
|
|
+ void define(String routePath,
|
|
|
+ {@required Handler handler, TransitionType transitionType}) {
|
|
|
+ _routeTree.addRoute(
|
|
|
+ new AppRoute(routePath, handler, transitionType: transitionType));
|
|
|
}
|
|
|
|
|
|
/// Finds a defined [AppRoute] for the path value. If no [AppRoute] definition was found
|
|
@@ -50,7 +41,7 @@ class Router {
|
|
|
Future navigateTo(BuildContext context, String path,
|
|
|
{bool replace = false,
|
|
|
bool clearStack = false,
|
|
|
- TransitionType transition = TransitionType.native,
|
|
|
+ TransitionType transition,
|
|
|
Duration transitionDuration = const Duration(milliseconds: 250),
|
|
|
RouteTransitionsBuilder transitionBuilder}) {
|
|
|
RouteMatch routeMatch = matchRoute(context, path,
|
|
@@ -112,6 +103,10 @@ class Router {
|
|
|
AppRouteMatch match = _routeTree.matchRoute(path);
|
|
|
AppRoute route = match?.route;
|
|
|
Handler handler = (route != null ? route.handler : notFoundHandler);
|
|
|
+ var transition = transitionType;
|
|
|
+ if (transitionType == null) {
|
|
|
+ transition = route != null ? route.transitionType : TransitionType.native;
|
|
|
+ }
|
|
|
if (route == null && notFoundHandler == null) {
|
|
|
return new RouteMatch(
|
|
|
matchType: RouteMatchType.noMatch,
|
|
@@ -126,21 +121,21 @@ class Router {
|
|
|
|
|
|
RouteCreator creator =
|
|
|
(RouteSettings routeSettings, Map<String, List<String>> parameters) {
|
|
|
- bool isNativeTransition = (transitionType == TransitionType.native ||
|
|
|
- transitionType == TransitionType.nativeModal);
|
|
|
+ bool isNativeTransition = (transition == TransitionType.native ||
|
|
|
+ transition == TransitionType.nativeModal);
|
|
|
if (isNativeTransition) {
|
|
|
return new MaterialPageRoute<dynamic>(
|
|
|
settings: routeSettings,
|
|
|
- fullscreenDialog: transitionType == TransitionType.nativeModal,
|
|
|
+ fullscreenDialog: transition == TransitionType.nativeModal,
|
|
|
builder: (BuildContext context) {
|
|
|
return handler.handlerFunc(context, parameters);
|
|
|
});
|
|
|
} else {
|
|
|
var routeTransitionsBuilder;
|
|
|
- if (transitionType == TransitionType.custom) {
|
|
|
+ if (transition == TransitionType.custom) {
|
|
|
routeTransitionsBuilder = transitionsBuilder;
|
|
|
} else {
|
|
|
- routeTransitionsBuilder = _standardTransitionsBuilder(transitionType);
|
|
|
+ routeTransitionsBuilder = _standardTransitionsBuilder(transition);
|
|
|
}
|
|
|
return new PageRouteBuilder<dynamic>(
|
|
|
settings: routeSettings,
|