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._rootVRouter] 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(Animation<double> animation, 77 : Animation<double> secondaryAnimation, Widget child)? buildTransition; 78 : 79 13 : VWidget({ 80 : required this.path, 81 : required this.widget, 82 : this.stackedRoutes = const [], 83 : this.key, 84 : this.name, 85 : this.aliases = const [], 86 : this.mustMatchStackedRoute = false, 87 : this.transitionDuration, 88 : this.reverseTransitionDuration, 89 : this.buildTransition, 90 : }); 91 : 92 13 : @override 93 13 : List<VRouteElement> buildRoutes() => [ 94 13 : VPath( 95 13 : path: path, 96 13 : aliases: aliases, 97 13 : mustMatchStackedRoute: mustMatchStackedRoute, 98 13 : stackedRoutes: [ 99 13 : VWidgetBase( 100 13 : widget: widget, 101 13 : key: key, 102 13 : name: name, 103 13 : stackedRoutes: stackedRoutes, 104 13 : buildTransition: buildTransition, 105 13 : transitionDuration: transitionDuration, 106 13 : reverseTransitionDuration: reverseTransitionDuration, 107 : ), 108 : ], 109 : ), 110 : ]; 111 : }