of method

ActionDispatcher of (
  1. BuildContext context,
  2. {bool nullOk: false}
)

Returns the ActionDispatcher associated with the Actions widget that most tightly encloses the given BuildContext.

Will throw if no ambient Actions widget is found.

If nullOk is set to true, then if no ambient Actions widget is found, this will return null.

The context argument must not be null.

Implementation

static ActionDispatcher of(BuildContext context, {bool nullOk = false}) {
  assert(context != null);
  final InheritedElement inheritedElement = context.getElementForInheritedWidgetOfExactType<Actions>();
  final Actions inherited = context.dependOnInheritedElement(inheritedElement) as Actions;
  assert(() {
    if (nullOk) {
      return true;
    }
    if (inherited == null) {
      throw FlutterError('Unable to find an $Actions widget in the context.\n'
          '$Actions.of() was called with a context that does not contain an '
          '$Actions widget.\n'
          'No $Actions ancestor could be found starting from the context that '
          'was passed to $Actions.of(). This can happen if the context comes '
          'from a widget above those widgets.\n'
          'The context used was:\n'
          '  $context');
    }
    return true;
  }());
  return inherited?.dispatcher ?? _findDispatcher(inheritedElement);
}