LCOV - code coverage report
Current view: top level - src - transition_delegates.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 34 34 100.0 %
Date: 2021-12-12 20:09:16 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/widgets.dart';
       2             : 
       3             : /// A no-animation transition delegate for [BeamerDelegate.transitionDelegate].
       4             : ///
       5             : /// See example at https://api.flutter.dev/flutter/widgets/TransitionDelegate-class.html.
       6             : class NoAnimationTransitionDelegate extends TransitionDelegate<void> {
       7             :   /// Creates a [NoAnimationTransitionDelegate].
       8           2 :   const NoAnimationTransitionDelegate() : super();
       9             : 
      10           2 :   @override
      11             :   Iterable<RouteTransitionRecord> resolve({
      12             :     required List<RouteTransitionRecord> newPageRouteHistory,
      13             :     required Map<RouteTransitionRecord?, RouteTransitionRecord>
      14             :         locationToExitingPageRoute,
      15             :     required Map<RouteTransitionRecord?, List<RouteTransitionRecord>>
      16             :         pageRouteToPagelessRoutes,
      17             :   }) {
      18           2 :     final results = <RouteTransitionRecord>[];
      19             : 
      20           4 :     for (final pageRoute in newPageRouteHistory) {
      21           2 :       if (pageRoute.isWaitingForEnteringDecision) {
      22           2 :         pageRoute.markForAdd();
      23             :       }
      24           2 :       results.add(pageRoute);
      25             :     }
      26           4 :     for (final exitingPageRoute in locationToExitingPageRoute.values) {
      27           2 :       if (exitingPageRoute.isWaitingForExitingDecision) {
      28           2 :         exitingPageRoute.markForRemove();
      29           2 :         final pagelessRoutes = pageRouteToPagelessRoutes[exitingPageRoute];
      30             :         if (pagelessRoutes != null) {
      31           2 :           for (final pagelessRoute in pagelessRoutes) {
      32           1 :             pagelessRoute.markForRemove();
      33             :           }
      34             :         }
      35             :       }
      36           2 :       results.add(exitingPageRoute);
      37             :     }
      38             :     return results;
      39             :   }
      40             : }
      41             : 
      42             : /// A transition delegate that will look like pop, regardless of whether an action is actuallly a pop.
      43             : ///
      44             : /// New pages are added behind and then the remove animation on old pages is done.
      45             : class ReverseTransitionDelegate extends TransitionDelegate<void> {
      46             :   /// Creates a [ReverseTransitionDelegate],
      47          13 :   const ReverseTransitionDelegate() : super();
      48             : 
      49           4 :   @override
      50             :   Iterable<RouteTransitionRecord> resolve({
      51             :     required List<RouteTransitionRecord> newPageRouteHistory,
      52             :     required Map<RouteTransitionRecord?, RouteTransitionRecord>
      53             :         locationToExitingPageRoute,
      54             :     required Map<RouteTransitionRecord?, List<RouteTransitionRecord>>
      55             :         pageRouteToPagelessRoutes,
      56             :   }) {
      57           4 :     final results = <RouteTransitionRecord>[];
      58             : 
      59           4 :     void handleExitingRoute(RouteTransitionRecord? location) {
      60           4 :       final exitingPageRoute = locationToExitingPageRoute[location];
      61             :       if (exitingPageRoute == null) return;
      62           4 :       if (exitingPageRoute.isWaitingForExitingDecision) {
      63             :         final hasPagelessRoute =
      64           4 :             pageRouteToPagelessRoutes.containsKey(exitingPageRoute);
      65          12 :         exitingPageRoute.markForPop(exitingPageRoute.route.currentResult);
      66             :         if (hasPagelessRoute) {
      67           1 :           final pagelessRoutes = pageRouteToPagelessRoutes[exitingPageRoute]!;
      68           2 :           for (final pagelessRoute in pagelessRoutes) {
      69           1 :             if (pagelessRoute.isWaitingForExitingDecision) {
      70           3 :               pagelessRoute.markForPop(pagelessRoute.route.currentResult);
      71             :             }
      72             :           }
      73             :         }
      74             :       }
      75           4 :       results.add(exitingPageRoute);
      76             : 
      77           4 :       handleExitingRoute(exitingPageRoute);
      78             :     }
      79             : 
      80           8 :     for (final pageRoute in newPageRouteHistory) {
      81           4 :       if (pageRoute.isWaitingForEnteringDecision) {
      82           4 :         pageRoute.markForAdd();
      83             :       }
      84           4 :       results.add(pageRoute);
      85           4 :       handleExitingRoute(pageRoute);
      86             :     }
      87             : 
      88           4 :     handleExitingRoute(null);
      89             : 
      90             :     return results;
      91             :   }
      92             : }

Generated by: LCOV version 1.14