of static method

Keyboard of(
  1. BuildContext context
)

The keyboard of the surface context is mounted on.

Stable for the lifetime of one runApp: a driver swap clears state and bumps KeyboardSnapshot.sessionGeneration on the same handle rather than replacing it, so caching the handle in a State field is safe.

Implementation

static Keyboard of(BuildContext context) {
  final notifier = dependOnScope<KeyboardStateNotifier>(context);
  if (notifier == null) {
    throw StateError(
      'Keyboard.of() found no KeyboardScope.\n'
      'The scope is installed by runApp (and by the browser embed host), '
      'so this usually means the widget is being built outside a running '
      'app — in a bare BuildOwner test, mount FleuryTester or wrap the '
      'tree in a KeyboardScope.',
    );
  }
  return Keyboard._(notifier.session);
}