closeOverlay<T> function

Future<void> closeOverlay<T>(
  1. BuildContext context, [
  2. T? value
])

Closes the currently active overlay with an optional result value.

Searches up the widget tree for the OverlayCompleter of the overlay context is inside of (inherited by the overlay's own content) and requests it to close with the provided result. If none is found, returns a completed future.

Parameters:

  • context (BuildContext, required): Build context from within the overlay
  • value (T?): Optional result value to return when closing

Returns a Future that completes when the overlay is closed.

Example:

closeOverlay(context, 'user_confirmed');

Implementation

Future<void> closeOverlay<T>(BuildContext context, [T? value]) {
  return Data.maybeFind<OverlayCompleter>(context)?.closeWithResult(value) ??
      Future.value();
}