LCOV - code coverage report
Current view: top level - src/vroute_elements - vnester_base.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 12 12 100.0 %
Date: 2021-04-26 23:10:51 Functions: 0 0 -

          Line data    Source code
       1             : part of '../main.dart';
       2             : 
       3             : /// A [VRouteElement] which enable nesting
       4             : ///
       5             : /// [widgetBuilder] gives you a [Widget] which is what you should use as the child to nest
       6             : /// This [Widget] will be the one present in the [VRouteElement] in [nestedRoutes] corresponding
       7             : /// to the current route
       8             : ///
       9             : /// {@tool snippet}
      10             : ///
      11             : /// If you want to nest ProfileWidget in MyScaffold at the path '/profile',
      12             : /// here is what you can do:
      13             : ///
      14             : /// ```dart
      15             : /// VNester(
      16             : ///   widgetBuilder: (child) => MyScaffold(child: child),
      17             : ///   nestedRoutes: [
      18             : ///     VWidget(
      19             : ///       path: '/profile',
      20             : ///       widget: ProfileWidget(),
      21             : ///     ),
      22             : ///   ],
      23             : /// )
      24             : /// ```
      25             : /// {@end-tool}
      26             : ///
      27             : ///
      28             : /// {@tool snippet}
      29             : ///
      30             : /// Note that you can also use stackedRoutes if you want to nest AND stack by using nestedRoutes
      31             : /// AND stackedRoutes:
      32             : ///
      33             : /// ```dart
      34             : /// VNester(
      35             : ///   path: '/home',
      36             : ///   widgetBuilder: (child) => MyScaffold(child: child),
      37             : ///   nestedRoutes: [
      38             : ///     VWidget(
      39             : ///       path: 'profile',
      40             : ///       alias: [':_(settings)'] // This is used because we want to display ProfileWidget while SettingsWidgets is on top of MyScaffold
      41             : ///       widget: ProfileWidget(),
      42             : ///     ),
      43             : ///   ],
      44             : ///   stackedRoutes: [
      45             : ///     VWidget(
      46             : ///       path: 'settings',
      47             : ///       widget: SettingsWidget(),
      48             : ///     ),
      49             : ///   ],
      50             : /// )
      51             : /// ```
      52             : ///
      53             : /// Also see:
      54             : ///   * [VNester] for a [VRouteElement] similar to [VNesterBase] but which take path information
      55             : /// {@end-tool}
      56             : class VNesterBase extends VRouteElementBuilder {
      57             :   /// A list of [VRouteElement] which widget will be accessible in [widgetBuilder]
      58             :   final List<VRouteElement> nestedRoutes;
      59             : 
      60             :   /// A list of routes which:
      61             :   ///   - path NOT starting with '/' will be relative to [path]
      62             :   ///   - widget or page will be stacked on top of [widget]
      63             :   final List<VRouteElement> stackedRoutes;
      64             : 
      65             :   /// A function which creates the [VRouteElement.widget] associated to this [VRouteElement]
      66             :   ///
      67             :   /// [child] will be the [VRouteElement.widget] of the matched [VRouteElement] in
      68             :   /// [nestedRoutes]
      69             :   final Widget Function(Widget child) widgetBuilder;
      70             : 
      71             :   final LocalKey? key;
      72             : 
      73             :   /// The duration of [VWidgetBase.buildTransition]
      74             :   final Duration? transitionDuration;
      75             : 
      76             :   /// The reverse duration of [VWidgetBase.buildTransition]
      77             :   final Duration? reverseTransitionDuration;
      78             : 
      79             :   /// Create a custom transition effect when coming to and
      80             :   /// going to this route
      81             :   /// This has the priority over [VRouter.buildTransition]
      82             :   ///
      83             :   /// Also see:
      84             :   ///   * [VRouter.buildTransition] for default transitions for all routes
      85             :   final Widget Function(
      86             :           Animation<double> animation, Animation<double> secondaryAnimation, Widget child)?
      87             :       buildTransition;
      88             : 
      89           3 :   VNesterBase({
      90             :     required this.widgetBuilder,
      91             :     required this.nestedRoutes,
      92             :     this.transitionDuration,
      93             :     this.reverseTransitionDuration,
      94             :     this.buildTransition,
      95             :     this.key,
      96             :     this.stackedRoutes = const [],
      97             :   });
      98             : 
      99           3 :   @override
     100           3 :   List<VRouteElement> buildRoutes() => [
     101           3 :         VNesterPageBase(
     102           3 :           key: key,
     103           3 :           nestedRoutes: nestedRoutes,
     104           3 :           stackedRoutes: stackedRoutes,
     105           3 :           widgetBuilder: widgetBuilder,
     106           4 :           pageBuilder: (LocalKey key, Widget child) => VBasePage.fromPlatform(
     107             :             key: key,
     108             :             child: child,
     109           2 :             buildTransition: buildTransition,
     110           2 :             transitionDuration: transitionDuration,
     111           2 :             reverseTransitionDuration: reverseTransitionDuration,
     112             :           ),
     113             :         ),
     114             :       ];
     115             : }

Generated by: LCOV version 1.14