LCOV - code coverage report
Current view: top level - src - beamer_back_button_dispatcher.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 17 17 100.0 %
Date: 2021-07-18 19:09:57 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/material.dart';
       2             : 
       3             : import 'beamer_delegate.dart';
       4             : 
       5             : /// Overrides default back button behavior in [RootBackButtonDispatcher]
       6             : /// to do custom [onBack] or [BeamerDelegate.beamBack].
       7             : class BeamerBackButtonDispatcher extends RootBackButtonDispatcher {
       8           1 :   BeamerBackButtonDispatcher({
       9             :     required this.delegate,
      10             :     this.onBack,
      11             :   });
      12             : 
      13             :   /// A [BeamerDelegate] that belongs to the same [Router]/[Beamer] as this.
      14             :   final BeamerDelegate delegate;
      15             : 
      16             :   /// A custom closure that has precedence over the default behavior.
      17             :   ///
      18             :   /// Return `true` if back action can be handled and `false` otherwise.
      19             :   final Future<bool> Function(BeamerDelegate delegate)? onBack;
      20             : 
      21             :   @override
      22           1 :   Future<bool> invokeCallback(Future<bool> defaultValue) async {
      23           1 :     if (onBack != null) {
      24           4 :       return Future.value(await onBack!(delegate));
      25             :     }
      26           2 :     bool didPopRoute = await super.invokeCallback(defaultValue);
      27             :     if (didPopRoute) {
      28           1 :       return Future.value(didPopRoute);
      29             :     }
      30           3 :     return Future.value(delegate.beamBack());
      31             :   }
      32             : }
      33             : 
      34             : /// Overrides default back button behavior in [ChildBackButtonDispatcher]
      35             : /// to do custom [onBack] or [BeamerDelegate.beamBack].
      36             : class BeamerChildBackButtonDispatcher extends ChildBackButtonDispatcher {
      37           1 :   BeamerChildBackButtonDispatcher({
      38             :     required BackButtonDispatcher parent,
      39             :     required this.delegate,
      40             :     this.onBack,
      41           1 :   }) : super(parent);
      42             : 
      43             :   /// A [BeamerDelegate] that belongs to the same [Router]/[Beamer] as this.
      44             :   final BeamerDelegate delegate;
      45             : 
      46             :   /// A custom closure that has precedence over the default behavior.
      47             :   ///
      48             :   /// Return `true` if back action can be handled and `false` otherwise.
      49             :   final Future<bool> Function(BeamerDelegate delegate)? onBack;
      50             : 
      51             :   @override
      52           1 :   Future<bool> invokeCallback(Future<bool> defaultValue) async {
      53           2 :     if (!delegate.active) {
      54           1 :       return Future.value(false);
      55             :     }
      56           1 :     if (onBack != null) {
      57           4 :       return Future.value(await onBack!(delegate));
      58             :     }
      59           2 :     bool didPopRoute = await super.invokeCallback(defaultValue);
      60             :     if (didPopRoute) {
      61           1 :       return Future.value(didPopRoute);
      62             :     }
      63           3 :     return Future.value(delegate.beamBack());
      64             :   }
      65             : }

Generated by: LCOV version 1.14