1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-09 14:28:51 +00:00

Update Navigation and Routing sample (#851)

* Add duration parameter to FadeTransitionPage

* Use didChangeDependencies instead of didUpdateWidget

* Don't notify listeners if the path hasn't changed

* Update navigation sample WIP

* Use Link and RouteStateScope in settings screen

* update README

* use named parameters for Library.addBook()

* Make _handleAuthStateChanged synchronous

* add missing copyright headers

* Address code review comments

* Address code review comments
This commit is contained in:
John Ryan
2021-07-12 14:22:53 -07:00
committed by GitHub
parent d3c4645a42
commit 35f1670098
17 changed files with 298 additions and 78 deletions

View File

@@ -7,6 +7,11 @@ import 'package:path_to_regexp/path_to_regexp.dart';
import 'parsed_route.dart';
/// Used by [TemplateRouteParser] to guard access to routes.
///
/// Override this class to change the route that is returned by
/// [TemplateRouteParser.parseRouteInformation] if a condition is not met, for
/// example, if the user is not signed in.
abstract class RouteGuard<T> {
Future<T> redirect(T from);
}
@@ -17,11 +22,16 @@ class TemplateRouteParser extends RouteInformationParser<ParsedRoute> {
RouteGuard<ParsedRoute>? guard;
final ParsedRoute initialRoute;
TemplateRouteParser(List<String> pathTemplates,
{String? initialRoute = '/', this.guard})
: initialRoute =
TemplateRouteParser({
/// The list of allowed path templates (['/', '/users/:id'])
required List<String> allowedPaths,
/// The initial route
String? initialRoute = '/',
/// [RouteGuard] used to redirect.
this.guard,
}) : initialRoute =
ParsedRoute(initialRoute ?? '/', initialRoute ?? '/', {}, {}) {
for (var template in pathTemplates) {
for (var template in allowedPaths) {
_addRoute(template);
}
}