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

          Line data    Source code
       1             : part of '../main.dart';
       2             : 
       3             : /// If the [VRouteElement] does have a page to display, it should extend this class
       4             : ///
       5             : /// What is does is:
       6             : ///   - Requiring attribute [widget]
       7             : ///   - implementing [buildRoute] methods
       8             : @immutable
       9             : mixin VRouteElementWithPage on VRouteElement {
      10             :   List<VRouteElement> get stackedRoutes;
      11             : 
      12             :   /// The widget which will be displayed for the given [path]
      13             :   Page Function(LocalKey key, Widget child) get pageBuilder;
      14             : 
      15             :   /// The widget which will be put inside the page
      16             :   Widget get widget;
      17             : 
      18             :   /// The key associated to the page
      19             :   LocalKey? get key;
      20             : 
      21             :   /// This is basically the same as [VPath.buildRoute] except that
      22             :   /// we add the page of this [VRouteElement] as a page to [VRoute.pages]
      23          12 :   @override
      24             :   VRoute? buildRoute(
      25             :     VPathRequestData vPathRequestData, {
      26             :     required VPathMatch parentVPathMatch,
      27             :   }) {
      28             :     // Set localPath to null since a VRouteElementWithPage marks a limit between localPaths
      29          12 :     VPathMatch newVPathMatch = (parentVPathMatch is ValidVPathMatch)
      30          12 :         ? ValidVPathMatch(
      31          12 :             remainingPath: parentVPathMatch.remainingPath,
      32          12 :             pathParameters: parentVPathMatch.pathParameters,
      33             :             localPath: null,
      34             :           )
      35          12 :         : InvalidVPathMatch(localPath: null);
      36             : 
      37             :     VRoute? childVRoute;
      38          24 :     for (var vRouteElement in stackedRoutes) {
      39          12 :       childVRoute = vRouteElement.buildRoute(
      40             :         vPathRequestData,
      41             :         parentVPathMatch: newVPathMatch,
      42             :       );
      43             :       if (childVRoute != null) {
      44             :         break;
      45             :       }
      46             :     }
      47             : 
      48          36 :     final bool validParentVRoute = !(parentVPathMatch is InvalidVPathMatch) && (parentVPathMatch as ValidVPathMatch).remainingPath.isEmpty;
      49             :     if (childVRoute == null && !validParentVRoute) {
      50             :       return null;
      51             :     }
      52             : 
      53          12 :     final VRouteElementNode vRouteElementNode = VRouteElementNode(
      54             :       this,
      55             :       localPath: null,
      56          12 :       stackedVRouteElementNode: childVRoute?.vRouteElementNode,
      57             :     );
      58             : 
      59             :     Map<String, String> pathParameters =
      60          24 :         childVRoute?.pathParameters ?? (parentVPathMatch as ValidVPathMatch).pathParameters;
      61             : 
      62          12 :     return VRoute(
      63             :       vRouteElementNode: vRouteElementNode,
      64          12 :       pages: [
      65          24 :         pageBuilder(
      66          36 :           key ?? ValueKey(parentVPathMatch.localPath),
      67          12 :           LocalVRouterData(
      68          12 :             child: NotificationListener<VWidgetGuardMessage>(
      69             :               // This listen to [VWidgetGuardNotification] which is a notification
      70             :               // that a [VWidgetGuard] sends when it is created
      71             :               // When this happens, we store the VWidgetGuard and its context
      72             :               // This will be used to call its afterUpdate and beforeLeave in particular.
      73           1 :               onNotification: (VWidgetGuardMessage vWidgetGuardMessage) {
      74           1 :                 VWidgetGuardMessageRoot(
      75           1 :                   vWidgetGuard: vWidgetGuardMessage.vWidgetGuard,
      76           1 :                   localContext: vWidgetGuardMessage.localContext,
      77             :                   associatedVRouteElement: this,
      78           2 :                 ).dispatch(vPathRequestData.rootVRouterContext);
      79             : 
      80             :                 return true;
      81             :               },
      82          12 :               child: widget,
      83             :             ),
      84             :             vRouteElementNode: vRouteElementNode,
      85          12 :             url: vPathRequestData.url,
      86          12 :             previousUrl: vPathRequestData.previousUrl,
      87          12 :             historyState: vPathRequestData.historyState,
      88             :             pathParameters: pathParameters,
      89          12 :             queryParameters: vPathRequestData.queryParameters,
      90          12 :             context: vPathRequestData.rootVRouterContext,
      91             :           ),
      92             :         ),
      93          36 :         ...childVRoute?.pages ?? []
      94             :       ],
      95             :       pathParameters: pathParameters,
      96          48 :       vRouteElements: <VRouteElement>[this] + (childVRoute?.vRouteElements ?? []),
      97             :     );
      98             :   }
      99             : }

Generated by: LCOV version 1.14