maybeOf static method
The closest instance of DrawerController that encloses the given context, or null if none is found.
Typical usage is as follows:
DrawerController? controller = DrawerController.maybeOf(context);
Calling this method will create a dependency on the closest
DrawerController in the context, if there is one.
See also:
- DrawerController.of, which is similar to this method, but asserts if no DrawerController ancestor is found.
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.maybeOf(context);
/// ```
///
/// </callout-box>
///
/// Calling this method will create a dependency on the closest
/// [DrawerController] in the [context], if there is one.
///
/// See also:
///
/// * [DrawerController.of], which is similar to this method, but asserts
/// if no [DrawerController] ancestor is found.
static DrawerController? maybeOf(BuildContext context) {
return context.dependOnInheritedWidgetOfExactType<_DrawerControllerScope>()?.controller;
}