of static method

The closest instance of DrawerController that encloses the given context.

If no instance is found, this method will assert in debug mode and throw an exception in release mode.

Calling this method will create a dependency on the closest DrawerController in the context.

Typical usage is as follows:

DrawerController controller = DrawerController.of(context);

Implementation

// TODO(framework): Add unit tests to this code snippet.
// https://github.com/flutter/flutter/issues/188530
/// Typical usage is as follows:
///
/// ```dart
/// DrawerController controller = DrawerController.of(context);
/// ```
///
/// </callout-box>
static DrawerController of(BuildContext context) {
  final DrawerController? controller = maybeOf(context);
  assert(() {
    if (controller == null) {
      throw FlutterError(
        'DrawerController.of() was called with a context that does not '
        'contain a DrawerController widget.\n'
        'No DrawerController widget ancestor could be found starting from '
        'the context that was passed to DrawerController.of(). This can '
        'happen because you are using a widget that looks for a DrawerController '
        'ancestor, but no such ancestor exists.\n'
        'The context used was:\n'
        '  $context',
      );
    }
    return true;
  }());
  return controller!;
}