of method Null safety

ShortcutManager of(
  1. BuildContext context

Returns the ShortcutManager that most tightly encloses the given BuildContext.

If no Shortcuts widget encloses the context given, will assert in debug mode and throw an exception in release mode.

See also:

  • maybeOf, which is similar to this function, but will return null if it doesn't find a Shortcuts ancestor.


static ShortcutManager of(BuildContext context) {
  assert(context != null);
  final _ShortcutsMarker? inherited = context.dependOnInheritedWidgetOfExactType<_ShortcutsMarker>();
  assert(() {
    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!.manager;