addScopedWillPopCallback method

  1. @Deprecated('Use registerPopEntry or PopScope instead. ' 'This feature was deprecated after v3.12.0-1.0.pre.')
void addScopedWillPopCallback(
  1. WillPopCallback callback
)

Enables this route to veto attempts by the user to dismiss it.

This callback runs asynchronously and it's possible that it will be called after its route has been disposed. The callback should check State.mounted before doing anything.

A typical application of this callback would be to warn the user about unsaved Form data if the user attempts to back out of the form. In that case, use the Form.onWillPop property to register the callback.

See also:

  • WillPopScope, which manages the registration and unregistration process automatically.
  • Form, which provides an onWillPop callback that uses this mechanism.
  • willPop, which runs the callbacks added with this method.
  • removeScopedWillPopCallback, which removes a callback from the list that willPop checks.

Implementation

@Deprecated(
  'Use registerPopEntry or PopScope instead. '
  'This feature was deprecated after v3.12.0-1.0.pre.',
)
void addScopedWillPopCallback(WillPopCallback callback) {
  assert(_scopeKey.currentState != null, 'Tried to add a willPop callback to a route that is not currently in the tree.');
  _willPopCallbacks.add(callback);
}