popModal method

void popModal([
  1. dynamic result
])

Pops the ModalRoute from this BuildContext, if any is active.

Implementation

void popModal([dynamic result]) {
  if (mounted) {
    final NavigatorState navigator = Navigator.of(this);
    final ModalRoute? modal = ModalRoute.of(this);

    if (modal?.isActive == true) {
      if (modal?.isCurrent == true) {
        navigator.pop(result);
      } else {
        navigator.removeRoute(modal!);
      }
    }
  }
}