Line data Source code
1 : part of '../main.dart'; 2 : 3 : /// A [VRouteElement] similar to [VNester] but which allows you to specify your own page 4 : /// thanks to [pageBuilder] 5 : class VNesterPage extends VRouteElementBuilder { 6 : /// A list of routes which: 7 : /// - path NOT starting with '/' will be relative to [path] 8 : /// - widget or page will be nested inside [widgetBuilder] 9 : final List<VRouteElement> nestedRoutes; 10 : 11 : /// A list of routes which: 12 : /// - path NOT starting with '/' will be relative to [path] 13 : /// - widget or page will be stacked on top of [_rootVRouter] 14 : final List<VRouteElement> stackedRoutes; 15 : 16 : /// A function which allows you to use your own custom page 17 : /// 18 : /// You must use [child] as the child of your page (though you can wrap it in other widgets) 19 : /// 20 : /// [child] will basically be whatever you put in [_rootVRouter] 21 : final Page Function(LocalKey key, Widget child, String? name) pageBuilder; 22 : 23 : /// A function which creates the [VRouteElement._rootVRouter] associated to this [VRouteElement] 24 : /// 25 : /// [child] will be the [VRouteElement._rootVRouter] of the matched [VRouteElement] in 26 : /// [nestedRoutes] 27 : final Widget Function(Widget child) widgetBuilder; 28 : 29 : /// The path (relative or absolute) or this [VRouteElement] 30 : /// 31 : /// If the path of a subroute is exactly matched, this will be used in 32 : /// the route but might be covered by another [VRouteElement._rootVRouter] 33 : /// The value of the path ca have three form: 34 : /// * starting with '/': The path will be treated as a route path, 35 : /// this is useful to take full advantage of nested routes while 36 : /// conserving the freedom of path naming 37 : /// * not starting with '/': The path corresponding to this route 38 : /// will be the path of the parent route + this path. If this is used 39 : /// directly in the [VRouter] routes, a '/' will be added anyway 40 : /// * be null: In this case this path will match the parent path 41 : /// 42 : /// Note we use the package [path_to_regexp](https://pub.dev/packages/path_to_regexp) 43 : /// so you can use naming such as /user/:id to get the id (see [VRouteElementData.pathParameters] 44 : /// You can also use more advance technique using regexp directly in your path, for example 45 : /// '.*' will match any route, '/user/:id(\d+)' will match any route starting with user 46 : /// and followed by a digit. Here is a recap: 47 : /// | pattern | matched path | [VRouter.pathParameters] 48 : /// | /user/:username | /user/evan | { username: 'evan' } 49 : /// | /user/:id(\d+) | /user/123 | { id: '123' } 50 : /// | .* | every path | - 51 : final String? path; 52 : 53 : /// A name for the route which will allow you to easily navigate to it 54 : /// using [VRouter.of(context).pushNamed] 55 : /// 56 : /// Note that [name] should be unique w.r.t every [VRouteElement] 57 : final String? name; 58 : 59 : /// Alternative paths that will be matched to this route 60 : /// 61 : /// Note that path is match first, then every aliases in order 62 : final List<String> aliases; 63 : 64 : /// A boolean to indicate whether this can be a valid [VRouteElement] of the [VRoute] if no 65 : /// [VRouteElement] in its [stackedRoute] is matched 66 : /// 67 : /// This is mainly useful for [VRouteElement]s which are NOT [VRouteElementWithPage] 68 : final bool mustMatchStackedRoute; 69 : 70 : /// A LocalKey that will be given to the page which contains the given [_rootVRouter] 71 : /// 72 : /// This key mostly controls the page animation. If a page remains the same but the key is changes, 73 : /// the page gets animated 74 : /// The key is by default the value of the current [path] (or [aliases]) with 75 : /// the path parameters replaced 76 : /// 77 : /// Do provide a constant [key] if you don't want this page to animate even if [path] or 78 : /// [aliases] path parameters change 79 : final LocalKey? key; 80 : 81 1 : VNesterPage({ 82 : required this.path, 83 : required this.pageBuilder, 84 : required this.widgetBuilder, 85 : required this.nestedRoutes, 86 : this.key, 87 : this.name, 88 : this.stackedRoutes = const [], 89 : this.aliases = const [], 90 : this.mustMatchStackedRoute = false, 91 : }); 92 : 93 1 : @override 94 1 : List<VRouteElement> buildRoutes() => [ 95 1 : VPath( 96 1 : path: path, 97 1 : aliases: aliases, 98 1 : mustMatchStackedRoute: mustMatchStackedRoute, 99 1 : stackedRoutes: [ 100 1 : VNesterPageBase( 101 1 : key: key, 102 1 : name: name, 103 1 : nestedRoutes: nestedRoutes, 104 1 : stackedRoutes: stackedRoutes, 105 1 : widgetBuilder: widgetBuilder, 106 1 : pageBuilder: pageBuilder, 107 : ), 108 : ], 109 : ), 110 : ]; 111 : }