lukepighetti 5 лет назад
Родитель
Сommit
84fc898ee7
4 измененных файлов с 34 добавлено и 10 удалено
  1. 1 1
      lib/fluro.dart
  2. 14 6
      lib/src/common.dart
  3. 14 3
      lib/src/fluro_router.dart
  4. 5 0
      lib/src/tree.dart

+ 1 - 1
lib/fluro.dart

@@ -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;

+ 14 - 6
lib/src/common.dart

@@ -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;
@@ -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,
@@ -49,7 +55,7 @@ enum TransitionType {
   inFromRight,
   inFromBottom,
   fadeIn,
-  custom, // if using custom then you must also provide a transition
+  custom,
   material,
   materialFullScreenDialog,
   cupertino,
@@ -57,13 +63,14 @@ enum TransitionType {
   none,
 }
 
+/// The match type of the route.
 enum RouteMatchType {
   visual,
   nonVisual,
   noMatch,
 }
 
-///
+/// The route that was matched.
 class RouteMatch {
   RouteMatch(
       {this.matchType = RouteMatchType.noMatch,
@@ -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;

+ 14 - 3
lib/src/fluro_router.dart

@@ -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
@@ -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,
@@ -94,7 +106,6 @@ class FluroRouter {
     return future;
   }
 
-  ///
   Route<Null> _notFoundRoute(BuildContext context, String path,
       {bool maintainState}) {
     RouteCreator<Null> creator =
@@ -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,

+ 5 - 0
lib/src/tree.dart

@@ -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);
@@ -24,6 +26,7 @@ class AppRouteMatch {
   Map<String, List<String>> parameters = <String, List<String>>{};
 }
 
+/// A matched [RouteTreeNode]
 class RouteTreeNodeMatch {
   // constructors
   RouteTreeNodeMatch(this.node);
@@ -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);
@@ -56,6 +60,7 @@ class RouteTreeNode {
   }
 }
 
+/// A [RouteTree]
 class RouteTree {
   // private
   final List<RouteTreeNode> _nodes = <RouteTreeNode>[];