of method

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

Returns the ActionDispatcher that most tightly encloses the given BuildContext.

The context argument must not be null.

Implementation

static ShortcutManager of(BuildContext context, {bool nullOk = false}) {
  assert(context != null);
  final _ShortcutsMarker inherited = context.dependOnInheritedWidgetOfExactType<_ShortcutsMarker>();
  assert(() {
    if (nullOk) {
      return true;
    }
    if (inherited == null) {
      throw FlutterError('Unable to find a $Shortcuts widget in the context.\n'
          '$Shortcuts.of() was called with a context that does not contain a '
          '$Shortcuts widget.\n'
          'No $Shortcuts ancestor could be found starting from the context that was '
          'passed to $Shortcuts.of().\n'
          'The context used was:\n'
          '  $context');
    }
    return true;
  }());
  return inherited?.notifier;
}