LCOV - code coverage report
Current view: top level - src/vroute_elements - vguard.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 18 18 100.0 %
Date: 2021-04-29 14:25:52 Functions: 0 0 -

          Line data    Source code
       1             : part of '../main.dart';
       2             : 
       3             : /// [VGuard] is a [VRouteElement] which is used to control navigation changes
       4             : ///
       5             : /// Use [beforeEnter], [beforeLeave] or [beforeUpdate] to get navigation changes before
       6             : /// they take place. These methods will give you a [VRedirector] that you can use to:
       7             : ///   - know about the navigation changes [VRedirector.previousVRouterData] and [VRedirector.newVRouterData]
       8             : ///   - redirect using [VRedirector.push] or stop the navigation using [VRedirector.stopRedirection]
       9             : ///
      10             : /// Use [afterEnter] or [afterUpdate] to get notification changes after they happened. At this point
      11             : /// you can use [VRouter.of(context)] to get any information about the new route
      12             : ///
      13             : /// See also [VWidgetGuard] for a widget-level way of controlling navigation changes
      14             : class VGuard extends VRouteElementBuilder with VoidVPopHandler {
      15           1 :   @override
      16             :   Future<void> beforeEnter(VRedirector vRedirector) =>
      17           2 :       _beforeEnter(vRedirector);
      18             :   final Future<void> Function(VRedirector vRedirector) _beforeEnter;
      19             : 
      20           1 :   @override
      21             :   Future<void> beforeUpdate(VRedirector vRedirector) =>
      22           2 :       _beforeUpdate(vRedirector);
      23             :   final Future<void> Function(VRedirector vRedirector) _beforeUpdate;
      24             : 
      25           1 :   @override
      26             :   Future<void> beforeLeave(VRedirector vRedirector,
      27             :           void Function(Map<String, String> state) saveHistoryState) =>
      28           2 :       _beforeLeave(vRedirector, saveHistoryState);
      29             :   final Future<void> Function(VRedirector vRedirector,
      30             :       void Function(Map<String, String> state) saveHistoryState) _beforeLeave;
      31             : 
      32           1 :   @override
      33             :   void afterEnter(BuildContext context, String? from, String to) =>
      34           2 :       _afterEnter(context, from, to);
      35             :   final void Function(BuildContext context, String? from, String to)
      36             :       _afterEnter;
      37             : 
      38           1 :   @override
      39             :   void afterUpdate(BuildContext context, String? from, String to) =>
      40           2 :       _afterUpdate(context, from, to);
      41             :   final void Function(BuildContext context, String? from, String to)
      42             :       _afterUpdate;
      43             : 
      44             :   /// See [VRouteElement.buildRoutes]
      45             :   final List<VRouteElement> stackedRoutes;
      46             : 
      47           2 :   @override
      48           2 :   List<VRouteElement> buildRoutes() => stackedRoutes;
      49             : 
      50           2 :   VGuard({
      51             :     Future<void> Function(VRedirector vRedirector) beforeEnter =
      52             :         VGuard._voidBeforeEnter,
      53             :     Future<void> Function(VRedirector vRedirector) beforeUpdate =
      54             :         VGuard._voidBeforeUpdate,
      55             :     final Future<void> Function(VRedirector vRedirector,
      56             :             void Function(Map<String, String> state) saveHistoryState)
      57             :         beforeLeave = VGuard._voidBeforeLeave,
      58             :     void Function(BuildContext context, String? from, String to) afterEnter =
      59             :         VGuard._voidAfterEnter,
      60             :     void Function(BuildContext context, String? from, String to) afterUpdate =
      61             :         VGuard._voidAfterUpdate,
      62             :     required this.stackedRoutes,
      63             :   })   : _beforeEnter = beforeEnter,
      64             :         _beforeUpdate = beforeUpdate,
      65             :         _beforeLeave = beforeLeave,
      66             :         _afterEnter = afterEnter,
      67             :         _afterUpdate = afterUpdate;
      68             : 
      69             :   /// Default function for [VRouteElement.beforeEnter]
      70             :   /// Basically does nothing
      71          12 :   static Future<void> _voidBeforeEnter(VRedirector vRedirector) async {}
      72             : 
      73             :   /// Default function for [VRouteElement.beforeUpdate]
      74             :   /// Basically does nothing
      75           2 :   static Future<void> _voidBeforeUpdate(VRedirector vRedirector) async {}
      76             : 
      77             :   /// Default function for [VRouteElement.beforeLeave]
      78             :   /// Basically does nothing
      79          10 :   static Future<void> _voidBeforeLeave(
      80             :     VRedirector? vRedirector,
      81             :     void Function(Map<String, String> state) saveHistoryState,
      82             :   ) async {}
      83             : 
      84             :   /// Default function for [VRouteElement.afterEnter]
      85             :   /// Basically does nothing
      86          12 :   static void _voidAfterEnter(BuildContext context, String? from, String to) {}
      87             : 
      88             :   /// Default function for [VRouteElement.afterUpdate]
      89             :   /// Basically does nothing
      90           1 :   static void _voidAfterUpdate(BuildContext context, String? from, String to) {}
      91             : }

Generated by: LCOV version 1.14