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-26 23:10:51 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           2 :   Future<void> beforeEnter(VRedirector vRedirector) => _beforeEnter(vRedirector);
      17             :   final Future<void> Function(VRedirector vRedirector) _beforeEnter;
      18             : 
      19           1 :   @override
      20           2 :   Future<void> beforeUpdate(VRedirector vRedirector) => _beforeUpdate(vRedirector);
      21             :   final Future<void> Function(VRedirector vRedirector) _beforeUpdate;
      22             : 
      23           1 :   @override
      24             :   Future<void> beforeLeave(VRedirector vRedirector,
      25             :           void Function(Map<String, String> state) saveHistoryState) =>
      26           2 :       _beforeLeave(vRedirector, saveHistoryState);
      27             :   final Future<void> Function(
      28             :           VRedirector vRedirector, void Function(Map<String, String> state) saveHistoryState)
      29             :       _beforeLeave;
      30             : 
      31           1 :   @override
      32             :   void afterEnter(BuildContext context, String? from, String to) =>
      33           2 :       _afterEnter(context, from, to);
      34             :   final void Function(BuildContext context, String? from, String to) _afterEnter;
      35             : 
      36           1 :   @override
      37             :   void afterUpdate(BuildContext context, String? from, String to) =>
      38           2 :       _afterUpdate(context, from, to);
      39             :   final void Function(BuildContext context, String? from, String to) _afterUpdate;
      40             : 
      41             :   /// See [VRouteElement.buildRoutes]
      42             :   final List<VRouteElement> stackedRoutes;
      43             : 
      44           2 :   @override
      45           2 :   List<VRouteElement> buildRoutes() => stackedRoutes;
      46             : 
      47           2 :   VGuard({
      48             :     Future<void> Function(VRedirector vRedirector) beforeEnter = VGuard._voidBeforeEnter,
      49             :     Future<void> Function(VRedirector vRedirector) beforeUpdate = VGuard._voidBeforeUpdate,
      50             :     final Future<void> Function(
      51             :             VRedirector vRedirector, void Function(Map<String, String> state) saveHistoryState)
      52             :         beforeLeave = VGuard._voidBeforeLeave,
      53             :     void Function(BuildContext context, String? from, String to) afterEnter =
      54             :         VGuard._voidAfterEnter,
      55             :     void Function(BuildContext context, String? from, String to) afterUpdate =
      56             :         VGuard._voidAfterUpdate,
      57             :     required this.stackedRoutes,
      58             :   })  : _beforeEnter = beforeEnter,
      59             :         _beforeUpdate = beforeUpdate,
      60             :         _beforeLeave = beforeLeave,
      61             :         _afterEnter = afterEnter,
      62             :         _afterUpdate = afterUpdate;
      63             : 
      64             :   /// Default function for [VRouteElement.beforeEnter]
      65             :   /// Basically does nothing
      66          12 :   static Future<void> _voidBeforeEnter(VRedirector vRedirector) async {}
      67             : 
      68             :   /// Default function for [VRouteElement.beforeUpdate]
      69             :   /// Basically does nothing
      70           2 :   static Future<void> _voidBeforeUpdate(VRedirector vRedirector) async {}
      71             : 
      72             :   /// Default function for [VRouteElement.beforeLeave]
      73             :   /// Basically does nothing
      74          10 :   static Future<void> _voidBeforeLeave(
      75             :     VRedirector? vRedirector,
      76             :     void Function(Map<String, String> state) saveHistoryState,
      77             :   ) async {}
      78             : 
      79             :   /// Default function for [VRouteElement.afterEnter]
      80             :   /// Basically does nothing
      81          12 :   static void _voidAfterEnter(BuildContext context, String? from, String to) {}
      82             : 
      83             :   /// Default function for [VRouteElement.afterUpdate]
      84             :   /// Basically does nothing
      85           1 :   static void _voidAfterUpdate(BuildContext context, String? from, String to) {}
      86             : }

Generated by: LCOV version 1.14