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