Skip to content

Commit

Permalink
All hail dartdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
lukepighetti committed Oct 20, 2020
1 parent a6f8b96 commit 84fc898
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/fluro.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Created by Yakka
* https://theyakka.com
*
* Copyright (c) 2019 Yakka, LLC. All rights reserved.
* Copyright (c) 2020 Luke Pighetti. All rights reserved.
* See LICENSE for distribution and usage details.
*/
library fluro;
Expand Down
20 changes: 14 additions & 6 deletions lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,31 @@

import 'package:flutter/widgets.dart';

///
/// The type of the handler, whether it's a buildable route or
/// a function that is called when routed.
enum HandlerType {
route,
function,
}

///
/// The handler to register with [FluroRouter.define]
class Handler {
Handler({this.type = HandlerType.route, this.handlerFunc});
final HandlerType type;
final HandlerFunc handlerFunc;
}

///
/// A function that creates new routes.
typedef Route<T> RouteCreator<T>(
RouteSettings route, Map<String, List<String>> parameters);

/// Builds out a screen based on string path [parameters] and context.
///
/// Note: you can access [RouteSettings] with the [context.settings] extension
typedef Widget HandlerFunc(
BuildContext context, Map<String, List<String>> parameters);

///
/// A route that is added to the router tree.
class AppRoute {
String route;
dynamic handler;
Expand All @@ -41,6 +44,9 @@ class AppRoute {
{this.transitionType, this.transitionDuration, this.transitionBuilder});
}

/// The type of transition to use when pushing/popping a route.
///
/// [TransitionType.custom] must also provide a transition when used.
enum TransitionType {
native,
nativeModal,
Expand All @@ -49,21 +55,22 @@ enum TransitionType {
inFromRight,
inFromBottom,
fadeIn,
custom, // if using custom then you must also provide a transition
custom,
material,
materialFullScreenDialog,
cupertino,
cupertinoFullScreenDialog,
none,
}

/// The match type of the route.
enum RouteMatchType {
visual,
nonVisual,
noMatch,
}

///
/// The route that was matched.
class RouteMatch {
RouteMatch(
{this.matchType = RouteMatchType.noMatch,
Expand All @@ -74,6 +81,7 @@ class RouteMatch {
final String errorMessage;
}

/// When the route is not found.
class RouteNotFoundException implements Exception {
final String message;
final String path;
Expand Down
17 changes: 14 additions & 3 deletions lib/src/fluro_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

/// {@template fluro_router}
/// Attach [FluroRouter] to [MaterialApp] by connnecting [FluroRouter.generator] to [MaterialApp.onGenerateRoute].
///
/// Define routes with [FluroRouter.define], optionally specifying transition types and connecting string path params to
/// your screen widget's constructor.
///
/// Push new route paths with [FluroRouter.appRouter.navigateTo] or continue to use [Navigator.of(context).push] if you prefer.
/// {@endtemplate}
class FluroRouter {
/// The static / singleton instance of [FluroRouter]
///
/// {@macro fluro_router}
static final appRouter = FluroRouter();

/// The tree structure that stores the defined routes
Expand Down Expand Up @@ -44,10 +55,11 @@ class FluroRouter {
return _routeTree.matchRoute(path);
}

/// Similar to [Navigator.pop]
void pop<T>(BuildContext context, [T result]) =>
Navigator.of(context).pop(result);

///
/// Similar to [Navigator.push] but with a few extra features.
Future navigateTo(BuildContext context, String path,
{bool replace = false,
bool clearStack = false,
Expand Down Expand Up @@ -94,7 +106,6 @@ class FluroRouter {
return future;
}

///
Route<Null> _notFoundRoute(BuildContext context, String path,
{bool maintainState}) {
RouteCreator<Null> creator =
Expand All @@ -109,7 +120,7 @@ class FluroRouter {
return creator(RouteSettings(name: path), null);
}

///
/// Attempt to match a route to the provided [path].
RouteMatch matchRoute(BuildContext buildContext, String path,
{RouteSettings routeSettings,
TransitionType transitionType,
Expand Down
5 changes: 5 additions & 0 deletions lib/src/tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import 'package:fluro/src/common.dart';
import 'package:flutter/widgets.dart';

/// A [RouteTreeNote] type
enum RouteTreeNodeType {
component,
parameter,
}

/// A matched [AppRoute]
class AppRouteMatch {
// constructors
AppRouteMatch(this.route);
Expand All @@ -24,6 +26,7 @@ class AppRouteMatch {
Map<String, List<String>> parameters = <String, List<String>>{};
}

/// A matched [RouteTreeNode]
class RouteTreeNodeMatch {
// constructors
RouteTreeNodeMatch(this.node);
Expand All @@ -40,6 +43,7 @@ class RouteTreeNodeMatch {
Map<String, List<String>> parameters = <String, List<String>>{};
}

/// A node on [RouteTree]
class RouteTreeNode {
// constructors
RouteTreeNode(this.part, this.type);
Expand All @@ -56,6 +60,7 @@ class RouteTreeNode {
}
}

/// A [RouteTree]
class RouteTree {
// private
final List<RouteTreeNode> _nodes = <RouteTreeNode>[];
Expand Down

0 comments on commit 84fc898

Please sign in to comment.