LCOV - code coverage report
Current view: top level - src/navigation/router - meedu_page_route.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 36 36 100.0 %
Date: 2022-11-04 14:47:16 Functions: 0 0 -

          Line data    Source code
       1             : // ignore_for_file: avoid_shadowing_type_parameters, avoid_renaming_method_parameters, public_member_api_docs
       2             : 
       3             : import 'package:flutter/cupertino.dart' show CupertinoApp;
       4             : import 'package:flutter/material.dart';
       5             : 
       6             : import '../gesture_detector/back_gesture_controller.dart';
       7             : import '../gesture_detector/gesture_detector.dart';
       8             : import '../transitions/export.dart';
       9             : import 'contextless_navigator.dart';
      10             : 
      11             : /// custom PageRoute for custom transitions in the router module
      12             : class MeeduPageRoute<T> extends PageRoute<T> {
      13           4 :   MeeduPageRoute({
      14             :     Widget? child,
      15             :     this.routeName,
      16             :     @required RouteSettings? settings,
      17             :     required this.maintainState,
      18             :     required this.transitionDuration,
      19             :     required bool fullscreenDialog,
      20             :     this.barrierColor,
      21             :     this.barrierLabel,
      22             :     required this.transition,
      23             :     required this.backGestureEnabled,
      24           4 :   }) : super(
      25             :           settings: settings,
      26             :           fullscreenDialog: fullscreenDialog,
      27             :         ) {
      28             :     if (child != null) {
      29           3 :       this.child = child;
      30             :     }
      31             :   }
      32             : 
      33             :   @override
      34             :   final Duration transitionDuration;
      35             : 
      36             :   @override
      37             :   final bool maintainState;
      38             : 
      39             :   @override
      40             :   final Color? barrierColor;
      41             : 
      42             :   @override
      43             :   final String? barrierLabel;
      44             : 
      45             :   final Transition transition;
      46             : 
      47             :   /// page content for the current route
      48             :   late Widget child;
      49             : 
      50             :   /// this value wont't be  null if the navigation
      51             :   /// was used throught a named route
      52             :   final String? routeName;
      53             : 
      54             :   /// if the back gesture to pop a page is enabled
      55             :   final bool backGestureEnabled;
      56             : 
      57             :   @override // coverage:ignore-line
      58             :   Widget buildPage(
      59             :     BuildContext context,
      60             :     Animation<double> animation,
      61             :     Animation<double> secondaryAnimation,
      62             :   ) {
      63             :     return child; // coverage:ignore-line
      64             :   }
      65             : 
      66           2 :   void build() {
      67          10 :     child = _getChild(ContextlessNavigator.i.appKey.currentContext!);
      68             :   }
      69             : 
      70           4 :   @override
      71             :   Widget buildTransitions(
      72             :     BuildContext context,
      73             :     Animation<double> animation,
      74             :     Animation<double> secondaryAnimation,
      75             :     Widget _,
      76             :   ) {
      77           4 :     switch (transition) {
      78           4 :       case Transition.downToUp:
      79           6 :         return DownToUpTransition().buildTransition(
      80             :           animation: animation,
      81           3 :           child: child,
      82             :         );
      83           3 :       case Transition.upToDown:
      84           2 :         return UpToDownTransition().buildTransition(
      85             :           animation: animation,
      86           1 :           child: child,
      87             :         );
      88             : 
      89           3 :       case Transition.rightToLeft:
      90           4 :         return RightToLeftTransition().buildTransition(
      91             :           animation: animation,
      92           2 :           child: child,
      93             :         );
      94             : 
      95           2 :       case Transition.fadeIn:
      96           1 :         return FadeTransition(
      97             :           opacity: animation,
      98           1 :           child: child,
      99             :         );
     100             : 
     101           2 :       case Transition.zoom:
     102           1 :         return ScaleTransition(
     103             :           scale: animation,
     104           1 :           child: child,
     105             :         );
     106             : 
     107             :       default:
     108           1 :         return child;
     109             :     }
     110             :   }
     111             : 
     112             :   /// check if [backGestureEnabled]is true and envolves it into a BackGestureDetector
     113           2 :   Widget _getChild(BuildContext context) {
     114           2 :     if (routeName != null) {
     115           6 :       final app = ContextlessNavigator.i.appKey.currentWidget;
     116             :       late Map<String, Widget Function(BuildContext)> routes;
     117           2 :       if (app is MaterialApp) {
     118           1 :         routes = app.routes ?? {};
     119             :       } else {
     120             :         // ignore: cast_nullable_to_non_nullable
     121           1 :         routes = (app as CupertinoApp).routes ?? {};
     122             :       }
     123             : 
     124             :       assert(
     125           6 :         routes.containsKey(routeName),
     126             :         'route name not found in your routes',
     127             :       );
     128           8 :       child = routes[routeName]!(context);
     129             :     }
     130           2 :     return backGestureEnabled
     131           2 :         ? BackGestureDetector(
     132           2 :             enabledCallback: _isPopGestureEnabled,
     133           2 :             onStartPopGesture: _startPopGesture,
     134           2 :             child: child,
     135             :           )
     136             :         : child; // coverage:ignore-line
     137             :   }
     138             : 
     139             :   // coverage:ignore-start
     140             :   BackGestureController<T> _startPopGesture<T>() {
     141             :     return BackGestureController<T>(
     142             :       navigator: navigator!,
     143             :       controller: controller!,
     144             :     );
     145             :   } // coverage:ignore-end
     146             : 
     147             :   // coverage:ignore-start
     148             :   bool get _isPopGestureInProgress {
     149             :     return navigator!.userGestureInProgress;
     150             :   } // coverage:ignore-end
     151             : 
     152             :   // coverage:ignore-start
     153             :   bool _isPopGestureEnabled<T>() {
     154             :     // ignore: lines_longer_than_80_chars
     155             :     if (isFirst ||
     156             :         willHandlePopInternally ||
     157             :         hasScopedWillPopCallback ||
     158             :         fullscreenDialog ||
     159             :         animation!.status != AnimationStatus.completed ||
     160             :         secondaryAnimation!.status != AnimationStatus.dismissed ||
     161             :         _isPopGestureInProgress) {
     162             :       return false;
     163             :     }
     164             : 
     165             :     return true;
     166             :   } // coverage:ignore-end
     167             : }

Generated by: LCOV version 1.16