|
@@ -12,14 +12,14 @@ import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:fluro/fluro.dart';
|
|
import 'package:fluro/fluro.dart';
|
|
|
import 'package:fluro/src/common.dart';
|
|
import 'package:fluro/src/common.dart';
|
|
|
-import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
+import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
class Router {
|
|
class Router {
|
|
|
- static final appRouter = new Router();
|
|
|
|
|
|
|
+ static final appRouter = Router();
|
|
|
|
|
|
|
|
/// The tree structure that stores the defined routes
|
|
/// The tree structure that stores the defined routes
|
|
|
- final RouteTree _routeTree = new RouteTree();
|
|
|
|
|
|
|
+ final RouteTree _routeTree = RouteTree();
|
|
|
|
|
|
|
|
/// Generic handler for when a route has not been defined
|
|
/// Generic handler for when a route has not been defined
|
|
|
Handler notFoundHandler;
|
|
Handler notFoundHandler;
|
|
@@ -28,7 +28,8 @@ class Router {
|
|
|
void define(String routePath,
|
|
void define(String routePath,
|
|
|
{@required Handler handler, TransitionType transitionType}) {
|
|
{@required Handler handler, TransitionType transitionType}) {
|
|
|
_routeTree.addRoute(
|
|
_routeTree.addRoute(
|
|
|
- new AppRoute(routePath, handler, transitionType: transitionType));
|
|
|
|
|
|
|
+ AppRoute(routePath, handler, transitionType: transitionType),
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Finds a defined [AppRoute] for the path value. If no [AppRoute] definition was found
|
|
/// Finds a defined [AppRoute] for the path value. If no [AppRoute] definition was found
|
|
@@ -51,7 +52,7 @@ class Router {
|
|
|
transitionsBuilder: transitionBuilder,
|
|
transitionsBuilder: transitionBuilder,
|
|
|
transitionDuration: transitionDuration);
|
|
transitionDuration: transitionDuration);
|
|
|
Route<dynamic> route = routeMatch.route;
|
|
Route<dynamic> route = routeMatch.route;
|
|
|
- Completer completer = new Completer();
|
|
|
|
|
|
|
+ Completer completer = Completer();
|
|
|
Future future = completer.future;
|
|
Future future = completer.future;
|
|
|
if (routeMatch.matchType == RouteMatchType.nonVisual) {
|
|
if (routeMatch.matchType == RouteMatchType.nonVisual) {
|
|
|
completer.complete("Non visual route type.");
|
|
completer.complete("Non visual route type.");
|
|
@@ -83,13 +84,13 @@ class Router {
|
|
|
Route<Null> _notFoundRoute(BuildContext context, String path) {
|
|
Route<Null> _notFoundRoute(BuildContext context, String path) {
|
|
|
RouteCreator<Null> creator =
|
|
RouteCreator<Null> creator =
|
|
|
(RouteSettings routeSettings, Map<String, List<String>> parameters) {
|
|
(RouteSettings routeSettings, Map<String, List<String>> parameters) {
|
|
|
- return new MaterialPageRoute<Null>(
|
|
|
|
|
|
|
+ return MaterialPageRoute<Null>(
|
|
|
settings: routeSettings,
|
|
settings: routeSettings,
|
|
|
builder: (BuildContext context) {
|
|
builder: (BuildContext context) {
|
|
|
return notFoundHandler.handlerFunc(context, parameters);
|
|
return notFoundHandler.handlerFunc(context, parameters);
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
- return creator(new RouteSettings(name: path), null);
|
|
|
|
|
|
|
+ return creator(RouteSettings(name: path), null);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
///
|
|
///
|
|
@@ -100,7 +101,7 @@ class Router {
|
|
|
RouteTransitionsBuilder transitionsBuilder}) {
|
|
RouteTransitionsBuilder transitionsBuilder}) {
|
|
|
RouteSettings settingsToUse = routeSettings;
|
|
RouteSettings settingsToUse = routeSettings;
|
|
|
if (routeSettings == null) {
|
|
if (routeSettings == null) {
|
|
|
- settingsToUse = new RouteSettings(name: path);
|
|
|
|
|
|
|
+ settingsToUse = RouteSettings(name: path);
|
|
|
}
|
|
}
|
|
|
AppRouteMatch match = _routeTree.matchRoute(path);
|
|
AppRouteMatch match = _routeTree.matchRoute(path);
|
|
|
AppRoute route = match?.route;
|
|
AppRoute route = match?.route;
|
|
@@ -110,7 +111,7 @@ class Router {
|
|
|
transition = route != null ? route.transitionType : TransitionType.native;
|
|
transition = route != null ? route.transitionType : TransitionType.native;
|
|
|
}
|
|
}
|
|
|
if (route == null && notFoundHandler == null) {
|
|
if (route == null && notFoundHandler == null) {
|
|
|
- return new RouteMatch(
|
|
|
|
|
|
|
+ return RouteMatch(
|
|
|
matchType: RouteMatchType.noMatch,
|
|
matchType: RouteMatchType.noMatch,
|
|
|
errorMessage: "No matching route was found");
|
|
errorMessage: "No matching route was found");
|
|
|
}
|
|
}
|
|
@@ -118,7 +119,7 @@ class Router {
|
|
|
match?.parameters ?? <String, List<String>>{};
|
|
match?.parameters ?? <String, List<String>>{};
|
|
|
if (handler.type == HandlerType.function) {
|
|
if (handler.type == HandlerType.function) {
|
|
|
handler.handlerFunc(buildContext, parameters);
|
|
handler.handlerFunc(buildContext, parameters);
|
|
|
- return new RouteMatch(matchType: RouteMatchType.nonVisual);
|
|
|
|
|
|
|
+ return RouteMatch(matchType: RouteMatchType.nonVisual);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
RouteCreator creator =
|
|
RouteCreator creator =
|
|
@@ -127,29 +128,38 @@ class Router {
|
|
|
transition == TransitionType.nativeModal);
|
|
transition == TransitionType.nativeModal);
|
|
|
if (isNativeTransition) {
|
|
if (isNativeTransition) {
|
|
|
if (Platform.isIOS) {
|
|
if (Platform.isIOS) {
|
|
|
- return new CupertinoPageRoute<dynamic>(
|
|
|
|
|
|
|
+ return CupertinoPageRoute<dynamic>(
|
|
|
settings: routeSettings,
|
|
settings: routeSettings,
|
|
|
fullscreenDialog: transition == TransitionType.nativeModal,
|
|
fullscreenDialog: transition == TransitionType.nativeModal,
|
|
|
builder: (BuildContext context) {
|
|
builder: (BuildContext context) {
|
|
|
return handler.handlerFunc(context, parameters);
|
|
return handler.handlerFunc(context, parameters);
|
|
|
});
|
|
});
|
|
|
- } else if (transition == TransitionType.cupertino ||
|
|
|
|
|
- transition == TransitionType.cupertinoFullScreenDialog) {
|
|
|
|
|
- return new CupertinoPageRoute<dynamic>(
|
|
|
|
|
- settings: routeSettings,
|
|
|
|
|
- fullscreenDialog:
|
|
|
|
|
- transition == TransitionType.cupertinoFullScreenDialog,
|
|
|
|
|
- builder: (BuildContext context) {
|
|
|
|
|
- return handler.handlerFunc(context, parameters);
|
|
|
|
|
- });
|
|
|
|
|
} else {
|
|
} else {
|
|
|
- return new MaterialPageRoute<dynamic>(
|
|
|
|
|
|
|
+ return MaterialPageRoute<dynamic>(
|
|
|
settings: routeSettings,
|
|
settings: routeSettings,
|
|
|
fullscreenDialog: transition == TransitionType.nativeModal,
|
|
fullscreenDialog: transition == TransitionType.nativeModal,
|
|
|
builder: (BuildContext context) {
|
|
builder: (BuildContext context) {
|
|
|
return handler.handlerFunc(context, parameters);
|
|
return handler.handlerFunc(context, parameters);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
+ } else if (transition == TransitionType.material ||
|
|
|
|
|
+ transition == TransitionType.materialFullScreenDialog) {
|
|
|
|
|
+ return MaterialPageRoute<dynamic>(
|
|
|
|
|
+ settings: routeSettings,
|
|
|
|
|
+ fullscreenDialog:
|
|
|
|
|
+ transition == TransitionType.materialFullScreenDialog,
|
|
|
|
|
+ builder: (BuildContext context) {
|
|
|
|
|
+ return handler.handlerFunc(context, parameters);
|
|
|
|
|
+ });
|
|
|
|
|
+ } else if (transition == TransitionType.cupertino ||
|
|
|
|
|
+ transition == TransitionType.cupertinoFullScreenDialog) {
|
|
|
|
|
+ return CupertinoPageRoute<dynamic>(
|
|
|
|
|
+ settings: routeSettings,
|
|
|
|
|
+ fullscreenDialog:
|
|
|
|
|
+ transition == TransitionType.cupertinoFullScreenDialog,
|
|
|
|
|
+ builder: (BuildContext context) {
|
|
|
|
|
+ return handler.handlerFunc(context, parameters);
|
|
|
|
|
+ });
|
|
|
} else {
|
|
} else {
|
|
|
var routeTransitionsBuilder;
|
|
var routeTransitionsBuilder;
|
|
|
if (transition == TransitionType.custom) {
|
|
if (transition == TransitionType.custom) {
|
|
@@ -157,7 +167,7 @@ class Router {
|
|
|
} else {
|
|
} else {
|
|
|
routeTransitionsBuilder = _standardTransitionsBuilder(transition);
|
|
routeTransitionsBuilder = _standardTransitionsBuilder(transition);
|
|
|
}
|
|
}
|
|
|
- return new PageRouteBuilder<dynamic>(
|
|
|
|
|
|
|
+ return PageRouteBuilder<dynamic>(
|
|
|
settings: routeSettings,
|
|
settings: routeSettings,
|
|
|
pageBuilder: (BuildContext context, Animation<double> animation,
|
|
pageBuilder: (BuildContext context, Animation<double> animation,
|
|
|
Animation<double> secondaryAnimation) {
|
|
Animation<double> secondaryAnimation) {
|
|
@@ -168,7 +178,7 @@ class Router {
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
- return new RouteMatch(
|
|
|
|
|
|
|
+ return RouteMatch(
|
|
|
matchType: RouteMatchType.visual,
|
|
matchType: RouteMatchType.visual,
|
|
|
route: creator(settingsToUse, parameters),
|
|
route: creator(settingsToUse, parameters),
|
|
|
);
|
|
);
|
|
@@ -179,7 +189,7 @@ class Router {
|
|
|
return (BuildContext context, Animation<double> animation,
|
|
return (BuildContext context, Animation<double> animation,
|
|
|
Animation<double> secondaryAnimation, Widget child) {
|
|
Animation<double> secondaryAnimation, Widget child) {
|
|
|
if (transitionType == TransitionType.fadeIn) {
|
|
if (transitionType == TransitionType.fadeIn) {
|
|
|
- return new FadeTransition(opacity: animation, child: child);
|
|
|
|
|
|
|
+ return FadeTransition(opacity: animation, child: child);
|
|
|
} else {
|
|
} else {
|
|
|
const Offset topLeft = const Offset(0.0, 0.0);
|
|
const Offset topLeft = const Offset(0.0, 0.0);
|
|
|
const Offset topRight = const Offset(1.0, 0.0);
|
|
const Offset topRight = const Offset(1.0, 0.0);
|
|
@@ -194,8 +204,8 @@ class Router {
|
|
|
endOffset = topLeft;
|
|
endOffset = topLeft;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return new SlideTransition(
|
|
|
|
|
- position: new Tween<Offset>(
|
|
|
|
|
|
|
+ return SlideTransition(
|
|
|
|
|
+ position: Tween<Offset>(
|
|
|
begin: startOffset,
|
|
begin: startOffset,
|
|
|
end: endOffset,
|
|
end: endOffset,
|
|
|
).animate(animation),
|
|
).animate(animation),
|