removeCurrentSnackBar method Null safety

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

ScaffoldMessengerState.removeCurrentSnackBar removes the current SnackBar (if any) immediately. This method should not be used, and will be depracted in the near future.

The removed snack bar does not run its normal exit animation. If there are any queued snack bars, they begin their entrance animation immediately.

See also:

Implementation

@Deprecated(
  'Use ScaffoldMessenger.removeCurrentSnackBar. '
  'This feature was deprecated after v1.23.0-14.0.pre.'
)
void removeCurrentSnackBar({ SnackBarClosedReason reason = SnackBarClosedReason.remove }) {
  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!.removeCurrentSnackBar(reason: reason);
    return;
  }

  if (_snackBars.isEmpty)
    return;
  final Completer<SnackBarClosedReason> completer = _snackBars.first._completer;
  if (!completer.isCompleted)
    completer.complete(reason);
  _snackBarTimer?.cancel();
  _snackBarTimer = null;
  _snackBarController!.value = 0.0;
}