LCOV - code coverage report
Current view: top level - src/routes/observers - route_observer.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 78 82 95.1 %
Date: 2020-06-11 02:57:29 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/widgets.dart';
       2             : import 'package:get/src/root/smart_management.dart';
       3             : import '../../get_main.dart';
       4             : 
       5             : class Routing {
       6             :   String current;
       7             :   String previous;
       8             :   Object args;
       9             :   String removed;
      10             :   Route<dynamic> route;
      11             :   bool isBack;
      12             :   bool isSnackbar;
      13             :   bool isBottomSheet;
      14             :   bool isDialog;
      15           8 :   Routing({
      16             :     this.current,
      17             :     this.previous,
      18             :     this.args,
      19             :     this.removed,
      20             :     this.route,
      21             :     this.isBack,
      22             :     this.isSnackbar,
      23             :     this.isBottomSheet,
      24             :     this.isDialog,
      25             :   });
      26             : }
      27             : 
      28             : class GetObserver extends NavigatorObserver {
      29             :   final Function(Routing) routing;
      30             : 
      31           3 :   GetObserver([this.routing]);
      32             : 
      33             :   Route<dynamic> route;
      34             :   bool isBack;
      35             :   bool isSnackbar;
      36             :   bool isBottomSheet;
      37             :   bool isDialog;
      38             :   String current;
      39             :   String previous;
      40             :   Object args;
      41             :   // String previousArgs;
      42             :   String removed;
      43             : 
      44           3 :   @override
      45             :   void didPush(Route<dynamic> route, Route<dynamic> previousRoute) {
      46           9 :     if ('${route?.settings?.name}' == 'snackbar') {
      47           5 :       if (Get.isLogEnable) print("[OPEN SNACKBAR] ${route?.settings?.name}");
      48           9 :     } else if ('${route?.settings?.name}' == 'bottomsheet') {
      49           5 :       if (Get.isLogEnable) print("[OPEN BOTTOMSHEET] ${route?.settings?.name}");
      50           9 :     } else if ('${route?.settings?.name}' == 'dialog') {
      51           5 :       if (Get.isLogEnable) print("[OPEN DIALOG] ${route?.settings?.name}");
      52             :     } else {
      53          15 :       if (Get.isLogEnable) print("[GOING TO ROUTE] ${route?.settings?.name}");
      54             :     }
      55             : 
      56          12 :     isSnackbar = '${route?.settings?.name}' == 'snackbar';
      57          12 :     isDialog = '${route?.settings?.name}' == 'dialog';
      58          12 :     isBottomSheet = '${route?.settings?.name}' == 'bottomsheet';
      59          12 :     current = '${route?.settings?.name}';
      60          12 :     previous = '${previousRoute?.settings?.name}';
      61           9 :     args = route?.settings?.arguments;
      62             :     // previousArgs = previousRoute?.settings?.arguments;
      63             : 
      64           3 :     final routeSend = Routing(
      65             :       removed: null,
      66             :       isBack: false,
      67             :       route: route,
      68           9 :       current: '${route?.settings?.name}',
      69           9 :       previous: '${previousRoute?.settings?.name}',
      70           6 :       args: route?.settings?.arguments,
      71             :       //  previousArgs: previousRoute?.settings?.arguments,
      72           3 :       isSnackbar: isSnackbar,
      73           3 :       isDialog: isDialog,
      74           3 :       isBottomSheet: isBottomSheet,
      75             :     );
      76           3 :     if (routing != null) {
      77           0 :       routing(routeSend);
      78             :     }
      79           3 :     Get.setRouting(routeSend);
      80             :   }
      81             : 
      82           3 :   @override
      83             :   void didPop(Route route, Route previousRoute) {
      84           3 :     super.didPop(route, previousRoute);
      85             : 
      86           9 :     if ('${route?.settings?.name}' == 'snackbar') {
      87           5 :       if (Get.isLogEnable) print("[CLOSE SNACKBAR] ${route?.settings?.name}");
      88           9 :     } else if ('${route?.settings?.name}' == 'bottomsheet') {
      89           1 :       if (Get.isLogEnable)
      90           4 :         print("[CLOSE BOTTOMSHEET] ${route?.settings?.name}");
      91           6 :     } else if ('${route?.settings?.name}' == 'dialog') {
      92           5 :       if (Get.isLogEnable) print("[CLOSE DIALOG] ${route?.settings?.name}");
      93             :     } else {
      94           5 :       if (Get.isLogEnable) print("[BACK ROUTE] ${route?.settings?.name}");
      95             :     }
      96             : 
      97           9 :     if (Get().smartManagement != SmartManagement.onlyBuilder) {
      98          15 :       Get().removeDependencyByRoute("${route?.settings?.name}");
      99             :     }
     100             : 
     101           3 :     isSnackbar = false;
     102           3 :     isDialog = false;
     103           3 :     isBottomSheet = false;
     104          12 :     current = '${previousRoute?.settings?.name}';
     105          12 :     previous = '${route?.settings?.name}';
     106           9 :     args = previousRoute?.settings?.arguments;
     107             :     // previousArgs = route?.settings?.arguments;
     108             : 
     109           3 :     final routeSend = Routing(
     110             :       removed: null,
     111             :       isBack: true,
     112             :       route: previousRoute,
     113           9 :       current: '${previousRoute?.settings?.name}',
     114           9 :       previous: '${route?.settings?.name}',
     115           6 :       args: previousRoute?.settings?.arguments,
     116             :       //  previousArgs: route?.settings?.arguments,
     117             :       isSnackbar: false, //'${route?.settings?.name}' == 'snackbar',
     118             :       isDialog: false, //'${route?.settings?.name}' == 'dialog',
     119             :       isBottomSheet: false, //'${route?.settings?.name}' == 'bottomsheet',
     120             :     );
     121             : 
     122           3 :     if (routing != null) {
     123           0 :       routing(routeSend);
     124             :     }
     125           3 :     Get.setRouting(routeSend);
     126             :   }
     127             : 
     128           1 :   @override
     129             :   void didReplace({Route newRoute, Route oldRoute}) {
     130           1 :     super.didReplace(newRoute: newRoute, oldRoute: oldRoute);
     131           5 :     if (Get.isLogEnable) print("[REPLACE ROUTE] ${oldRoute?.settings?.name}");
     132           5 :     if (Get.isLogEnable) print("[NEW ROUTE] ${newRoute?.settings?.name}");
     133             : 
     134           3 :     if (Get().smartManagement == SmartManagement.full) {
     135           5 :       Get().removeDependencyByRoute("${oldRoute?.settings?.name}");
     136             :     }
     137             : 
     138           1 :     isSnackbar = false;
     139           1 :     isDialog = false;
     140           1 :     isBottomSheet = false;
     141             : 
     142           1 :     final routeSend = Routing(
     143             :       removed: null, // add '${oldRoute?.settings?.name}' or remain null ???
     144             :       isBack: false,
     145             :       route: newRoute,
     146           3 :       current: '${newRoute?.settings?.name}',
     147           3 :       previous: '${oldRoute?.settings?.name}',
     148           2 :       args: newRoute?.settings?.arguments,
     149             :       //  previousArgs: newRoute?.settings?.arguments,
     150             :       isSnackbar: false,
     151             :       isBottomSheet: false,
     152             :       isDialog: false,
     153             :     );
     154             : 
     155           1 :     if (routing != null) {
     156           0 :       routing(routeSend);
     157             :     }
     158           1 :     Get.setRouting(routeSend);
     159             :   }
     160             : 
     161           1 :   @override
     162             :   void didRemove(Route route, Route previousRoute) {
     163           1 :     super.didRemove(route, previousRoute);
     164           5 :     if (Get.isLogEnable) print("[REMOVING ROUTE] ${route?.settings?.name}");
     165             : 
     166           3 :     if (Get().smartManagement == SmartManagement.full) {
     167           5 :       Get().removeDependencyByRoute("${route?.settings?.name}");
     168             :     }
     169             : 
     170           1 :     final routeSend = Routing(
     171             :       isBack: false,
     172             :       route: previousRoute,
     173             :       // current: '${previousRoute?.settings?.name}',
     174           1 :       current: current,
     175           1 :       args: args,
     176           3 :       removed: '${route?.settings?.name}',
     177             :       // args: previousRoute?.settings?.arguments,
     178           1 :       isSnackbar: isSnackbar,
     179           1 :       isBottomSheet: isBottomSheet,
     180           1 :       isDialog: isDialog,
     181             :       //   previousArgs: route?.settings?.arguments,
     182             :     );
     183             : 
     184           1 :     if (routing != null) {
     185           0 :       routing(routeSend);
     186             :     }
     187           1 :     Get.setRouting(routeSend);
     188             :   }
     189             : }

Generated by: LCOV version 1.14