bumped min dart to 2.0.0-dev (flutter min). formatting.

This commit is contained in:
Luke Freeman 2018-07-21 10:26:46 -07:00
parent 6b9a1822aa
commit e648217562
5 changed files with 67 additions and 42 deletions

View File

@ -14,4 +14,4 @@ import 'package:flutter/widgets.dart';
part 'src/common.dart';
part 'src/router.dart';
part 'src/tree.dart';
part 'src/tree.dart';

View File

@ -21,10 +21,12 @@ class Handler {
}
///
typedef Route<T> RouteCreator<T>(RouteSettings route, Map<String, List<String>> parameters);
typedef Route<T> RouteCreator<T>(
RouteSettings route, Map<String, List<String>> parameters);
///
typedef Widget HandlerFunc(BuildContext context, Map<String, List<String>> parameters);
typedef Widget HandlerFunc(
BuildContext context, Map<String, List<String>> parameters);
///
class AppRoute {
@ -41,12 +43,11 @@ enum RouteMatchType {
///
class RouteMatch {
RouteMatch({
this.matchType = RouteMatchType.noMatch,
this.route,
this.errorMessage = "Unable to match route. Please check the logs."
});
RouteMatch(
{this.matchType = RouteMatchType.noMatch,
this.route,
this.errorMessage = "Unable to match route. Please check the logs."});
final Route<dynamic> route;
final RouteMatchType matchType;
final String errorMessage;
}
}

View File

@ -18,7 +18,6 @@ enum TransitionType {
}
class Router {
static final appRouter = new Router();
/// The tree structure that stores the defined routes
@ -40,12 +39,15 @@ class Router {
}
///
Future navigateTo(BuildContext context, String path, {bool replace = false, TransitionType transition = TransitionType.native,
Duration transitionDuration = const Duration(milliseconds: 250),
RouteTransitionsBuilder transitionBuilder})
{
RouteMatch routeMatch = matchRoute(context, path, transitionType: transition,
transitionsBuilder: transitionBuilder, transitionDuration: transitionDuration);
Future navigateTo(BuildContext context, String path,
{bool replace = false,
TransitionType transition = TransitionType.native,
Duration transitionDuration = const Duration(milliseconds: 250),
RouteTransitionsBuilder transitionBuilder}) {
RouteMatch routeMatch = matchRoute(context, path,
transitionType: transition,
transitionsBuilder: transitionBuilder,
transitionDuration: transitionDuration);
Route<dynamic> route = routeMatch.route;
Completer completer = new Completer();
Future future = completer.future;
@ -56,7 +58,9 @@ class Router {
route = _notFoundRoute(context, path);
}
if (route != null) {
future = replace ? Navigator.pushReplacement(context, route) : Navigator.push(context, route);
future = replace
? Navigator.pushReplacement(context, route)
: Navigator.push(context, route);
completer.complete();
} else {
String error = "No registered route was found to handle '$path'.";
@ -70,19 +74,23 @@ class Router {
///
Route<Null> _notFoundRoute(BuildContext context, String path) {
RouteCreator<Null> creator = (RouteSettings routeSettings, Map<String, List<String>> parameters) {
return new MaterialPageRoute<Null>(settings: routeSettings, builder: (BuildContext context) {
return notFoundHandler.handlerFunc(context, parameters);
});
RouteCreator<Null> creator =
(RouteSettings routeSettings, Map<String, List<String>> parameters) {
return new MaterialPageRoute<Null>(
settings: routeSettings,
builder: (BuildContext context) {
return notFoundHandler.handlerFunc(context, parameters);
});
};
return creator(new RouteSettings(name: path), null);
}
///
RouteMatch matchRoute(BuildContext buildContext, String path, {RouteSettings routeSettings,
TransitionType transitionType, Duration transitionDuration = const Duration(milliseconds: 250),
RouteTransitionsBuilder transitionsBuilder})
{
RouteMatch matchRoute(BuildContext buildContext, String path,
{RouteSettings routeSettings,
TransitionType transitionType,
Duration transitionDuration = const Duration(milliseconds: 250),
RouteTransitionsBuilder transitionsBuilder}) {
RouteSettings settingsToUse = routeSettings;
if (routeSettings == null) {
settingsToUse = new RouteSettings(name: path);
@ -91,18 +99,25 @@ class Router {
AppRoute route = match?.route;
Handler handler = (route != null ? route.handler : notFoundHandler);
if (route == null && notFoundHandler == null) {
return new RouteMatch(matchType: RouteMatchType.noMatch, errorMessage: "No matching route was found");
return new RouteMatch(
matchType: RouteMatchType.noMatch,
errorMessage: "No matching route was found");
}
Map<String, List<String>> parameters = match?.parameters ?? <String, List<String>>{};
Map<String, List<String>> parameters =
match?.parameters ?? <String, List<String>>{};
if (handler.type == HandlerType.function) {
handler.handlerFunc(buildContext, parameters);
return new RouteMatch(matchType: RouteMatchType.nonVisual);
}
RouteCreator creator = (RouteSettings routeSettings, Map<String, List<String>> parameters) {
bool isNativeTransition = (transitionType == TransitionType.native || transitionType == TransitionType.nativeModal);
RouteCreator creator =
(RouteSettings routeSettings, Map<String, List<String>> parameters) {
bool isNativeTransition = (transitionType == TransitionType.native ||
transitionType == TransitionType.nativeModal);
if (isNativeTransition) {
return new MaterialPageRoute<dynamic>(settings: routeSettings, fullscreenDialog: transitionType == TransitionType.nativeModal,
return new MaterialPageRoute<dynamic>(
settings: routeSettings,
fullscreenDialog: transitionType == TransitionType.nativeModal,
builder: (BuildContext context) {
return handler.handlerFunc(context, parameters);
});
@ -113,8 +128,10 @@ class Router {
} else {
routeTransitionsBuilder = _standardTransitionsBuilder(transitionType);
}
return new PageRouteBuilder<dynamic>(settings: routeSettings,
pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
return new PageRouteBuilder<dynamic>(
settings: routeSettings,
pageBuilder: (BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation) {
return handler.handlerFunc(context, parameters);
},
transitionDuration: transitionDuration,
@ -128,8 +145,10 @@ class Router {
);
}
RouteTransitionsBuilder _standardTransitionsBuilder(TransitionType transitionType) {
return (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
RouteTransitionsBuilder _standardTransitionsBuilder(
TransitionType transitionType) {
return (BuildContext context, Animation<double> animation,
Animation<double> secondaryAnimation, Widget child) {
if (transitionType == TransitionType.fadeIn) {
return new FadeTransition(opacity: animation, child: child);
} else {
@ -161,7 +180,8 @@ class Router {
/// if any defined handler is found. It can also be used with the [MaterialApp.onGenerateRoute]
/// property as callback to create routes that can be used with the [Navigator] class.
Route<dynamic> generator(RouteSettings routeSettings) {
RouteMatch match = matchRoute(null, routeSettings.name, routeSettings: routeSettings);
RouteMatch match =
matchRoute(null, routeSettings.name, routeSettings: routeSettings);
return match.route;
}

View File

@ -39,8 +39,7 @@ class RouteTreeNodeMatch {
class RouteTreeNode {
// constructors
RouteTreeNode(this.part,
this.type);
RouteTreeNode(this.part, this.type);
// properties
String part;
@ -114,10 +113,12 @@ class RouteTree {
components = ["/"];
}
Map<RouteTreeNode, RouteTreeNodeMatch> nodeMatches = <RouteTreeNode, RouteTreeNodeMatch>{};
Map<RouteTreeNode, RouteTreeNodeMatch> nodeMatches =
<RouteTreeNode, RouteTreeNodeMatch>{};
List<RouteTreeNode> nodesToCheck = _nodes;
for (String checkComponent in components) {
Map<RouteTreeNode, RouteTreeNodeMatch> currentMatches = <RouteTreeNode, RouteTreeNodeMatch>{};
Map<RouteTreeNode, RouteTreeNodeMatch> currentMatches =
<RouteTreeNode, RouteTreeNodeMatch>{};
List<RouteTreeNode> nextNodes = <RouteTreeNode>[];
for (RouteTreeNode node in nodesToCheck) {
String pathPart = checkComponent;
@ -130,7 +131,8 @@ class RouteTree {
bool isMatch = (node.part == pathPart || node.isParameter());
if (isMatch) {
RouteTreeNodeMatch parentMatch = nodeMatches[node.parent];
RouteTreeNodeMatch match = new RouteTreeNodeMatch.fromMatch(parentMatch, node);
RouteTreeNodeMatch match =
new RouteTreeNodeMatch.fromMatch(parentMatch, node);
if (node.isParameter()) {
String paramKey = node.part.substring(1);
match.parameters[paramKey] = [pathPart];
@ -156,7 +158,9 @@ class RouteTree {
RouteTreeNodeMatch match = matches.first;
RouteTreeNode nodeToUse = match.node;
// print("using match: ${match}, ${nodeToUse?.part}, ${match?.parameters}");
if (nodeToUse != null && nodeToUse.routes != null && nodeToUse.routes.length > 0) {
if (nodeToUse != null &&
nodeToUse.routes != null &&
nodeToUse.routes.length > 0) {
List<AppRoute> routes = nodeToUse.routes;
AppRouteMatch routeMatch = new AppRouteMatch(routes[0]);
routeMatch.parameters = match.parameters;

View File

@ -5,7 +5,7 @@ author: Posse Productions LLC <apps@goposse.com>
homepage: https://github.com/goposse/fluro
environment:
sdk: ">=1.23.0 <2.0.0"
sdk: ">=2.0.0-dev.61.0 <3.0.0"
dependencies:
flutter: