hideCurrentSnackBar method

void hideCurrentSnackBar ({SnackBarClosedReason reason: SnackBarClosedReason.hide })

Removes the current SnackBar by running its normal exit animation.

The closed completer is called after the animation is complete.

Implementation

void hideCurrentSnackBar({ SnackBarClosedReason reason = SnackBarClosedReason.hide }) {
  assert(reason != null);
  if (_snackBars.isEmpty || _snackBarController.status == AnimationStatus.dismissed)
    return;
  final MediaQueryData mediaQuery = MediaQuery.of(context);
  final Completer<SnackBarClosedReason> completer = _snackBars.first._completer;
  if (mediaQuery.accessibleNavigation) {
    _snackBarController.value = 0.0;
    completer.complete(reason);
  } else {
    _snackBarController.reverse().then<void>((void value) {
      assert(mounted);
      if (!completer.isCompleted)
        completer.complete(reason);
    });
  }
  _snackBarTimer?.cancel();
  _snackBarTimer = null;
}