pushCancellableRoute<T extends Object?> method

Future<T?> pushCancellableRoute<T extends Object?>(
  1. Route<T> route,
  2. Cancellable? cancellable
)

推入一个可撤销的route

Implementation

Future<T?> pushCancellableRoute<T extends Object?>(
    Route<T> route, Cancellable? cancellable) {
  if (cancellable == null) return push<T>(route);
  if (cancellable.isUnavailable == true) {
    return Future.value(null);
  }

  final Cancellable showing = Cancellable();

  showing.bindCancellable(cancellable);
  showing.onCancel.then((value) => route.navigator?.removeRoute(route));

  return push<T>(route).whenComplete(() => showing.cancel());
}