hasDrawer static method

bool hasDrawer(
  1. BuildContext context, {
  2. bool registerForUpdates = true,
})

Whether the Scaffold that most tightly encloses the given context has a drawer.

If this is being used during a build (for example to decide whether to show an "open drawer" button), set the registerForUpdates argument to true. This will then set up an InheritedWidget relationship with the TransparentScaffold so that the client widget gets rebuilt whenever the hasDrawer value changes.

This method can be expensive (it walks the element tree).

See also:

Implementation

static bool hasDrawer(BuildContext context, {bool registerForUpdates = true}) {
  if (registerForUpdates) {
    final _ScaffoldScope? scaffold = context.dependOnInheritedWidgetOfExactType<_ScaffoldScope>();
    return scaffold?.hasDrawer ?? false;
  } else {
    final TransparentScaffoldState? scaffold =
        context.findAncestorStateOfType<TransparentScaffoldState>();
    return scaffold?.hasDrawer ?? false;
  }
}