2017-05-04 15:33:40 -04:00
|
|
|
/*
|
2017-05-14 01:01:02 -04:00
|
|
|
* fluro
|
2018-10-25 13:48:02 -04:00
|
|
|
* Created by Yakka
|
|
|
|
* https://theyakka.com
|
|
|
|
*
|
|
|
|
* Copyright (c) 2018 Yakka, LLC. All rights reserved.
|
2017-05-04 15:33:40 -04:00
|
|
|
* See LICENSE for distribution and usage details.
|
|
|
|
*/
|
2018-07-27 21:15:51 -04:00
|
|
|
|
|
|
|
import 'package:flutter/widgets.dart';
|
2017-04-25 03:24:14 -04:00
|
|
|
|
|
|
|
///
|
2017-05-28 13:13:36 -04:00
|
|
|
enum HandlerType {
|
|
|
|
route,
|
|
|
|
function,
|
|
|
|
}
|
2017-04-25 03:24:14 -04:00
|
|
|
|
|
|
|
///
|
2017-05-28 13:13:36 -04:00
|
|
|
class Handler {
|
|
|
|
Handler({this.type = HandlerType.route, this.handlerFunc});
|
|
|
|
final HandlerType type;
|
|
|
|
final HandlerFunc handlerFunc;
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
2018-07-21 13:26:46 -04:00
|
|
|
typedef Route<T> RouteCreator<T>(
|
|
|
|
RouteSettings route, Map<String, List<String>> parameters);
|
2017-05-28 13:13:36 -04:00
|
|
|
|
|
|
|
///
|
2018-07-21 13:26:46 -04:00
|
|
|
typedef Widget HandlerFunc(
|
|
|
|
BuildContext context, Map<String, List<String>> parameters);
|
2017-04-25 03:24:14 -04:00
|
|
|
|
|
|
|
///
|
|
|
|
class AppRoute {
|
|
|
|
String route;
|
2017-05-28 13:13:36 -04:00
|
|
|
dynamic handler;
|
2017-05-04 15:27:32 -04:00
|
|
|
AppRoute(this.route, this.handler);
|
2017-05-28 13:13:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
enum RouteMatchType {
|
|
|
|
visual,
|
|
|
|
nonVisual,
|
|
|
|
noMatch,
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
class RouteMatch {
|
2018-07-21 13:26:46 -04:00
|
|
|
RouteMatch(
|
|
|
|
{this.matchType = RouteMatchType.noMatch,
|
|
|
|
this.route,
|
|
|
|
this.errorMessage = "Unable to match route. Please check the logs."});
|
2017-10-13 20:10:21 -04:00
|
|
|
final Route<dynamic> route;
|
2017-05-28 13:13:36 -04:00
|
|
|
final RouteMatchType matchType;
|
|
|
|
final String errorMessage;
|
2018-07-21 13:26:46 -04:00
|
|
|
}
|
2018-10-25 13:48:02 -04:00
|
|
|
|
|
|
|
class RouteNotFoundException implements Exception {
|
2018-10-25 14:03:20 -04:00
|
|
|
final String message;
|
|
|
|
final String path;
|
|
|
|
RouteNotFoundException(this.message, this.path);
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return "No registered route was found to handle '$path'";
|
|
|
|
}
|
2018-10-25 13:48:02 -04:00
|
|
|
}
|