hideCurrentSnackBar method Null safety

  1. @Deprecated('Use ScaffoldMessenger.hideCurrentSnackBar. ' 'This feature was deprecated after v1.23.0-14.0.pre.')
void hideCurrentSnackBar(
  1. {SnackBarClosedReason reason = SnackBarClosedReason.hide}
)
@Deprecated('Use ScaffoldMessenger.hideCurrentSnackBar. ' 'This feature was deprecated after v1.23.0-14.0.pre.')

ScaffoldMessengerState.hideCurrentSnackBar removes the current SnackBar by running its normal exit animation. This method should not be used, and will be deprecated in the near future.

The closed completer is called after the animation is complete.

See also:

Implementation

@Deprecated(
  'Use ScaffoldMessenger.hideCurrentSnackBar. '
  'This feature was deprecated after v1.23.0-14.0.pre.',
)
void hideCurrentSnackBar({ SnackBarClosedReason reason = SnackBarClosedReason.hide }) {
  assert(reason != null);

  // SnackBars and SnackBarActions can call to hide and remove themselves, but
  // they are not aware of who presented them, the Scaffold or the
  // ScaffoldMessenger. As such, when the SnackBar classes call upon Scaffold
  // to remove (the current default), we should re-direct to the
  // ScaffoldMessenger here if that is where the SnackBar originated from.
  if (_messengerSnackBar != null) {
    // ScaffoldMessenger is presenting SnackBars.
    assert(debugCheckHasScaffoldMessenger(context));
    assert(
      _scaffoldMessenger != null,
      'A SnackBar was shown by the ScaffoldMessenger, but has been called upon '
      'to be removed from a Scaffold that is not registered with a '
      'ScaffoldMessenger, this can happen if a Scaffold has been rebuilt '
      'without an ancestor ScaffoldMessenger.',
    );
    _scaffoldMessenger!.hideCurrentSnackBar(reason: reason);
    return;
  }

  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;
}