maybeScaffold property

ScaffoldState? get maybeScaffold

Returns the nearest ScaffoldState instance for the current context or null if no Scaffold ancestor is found.

This is the nullable variant of scaffold that uses Scaffold.maybeOf instead of Scaffold.of. It allows you to safely attempt scaffold operations in widget trees where a Scaffold might not be present (for example inside isolated subtrees or tests) without throwing.

Example usage:

context.maybeScaffold?.showSnackBar(const SnackBar(content: Text('Hi!')));

Implementation

ScaffoldState? get maybeScaffold => Scaffold.maybeOf(this);