of static method
- BuildContext context
The PageStorageBucket from the closest instance of a PageStorage widget that encloses the given context.
If no ancestor is found, this method will assert in debug mode, and throw an exception in release mode.
Typical usage is as follows:
PageStorageBucket bucket = PageStorage.of(context);
This method can be expensive (it walks the element tree).
See also:
- PageStorage.maybeOf, which is similar to this method, but returns null if no PageStorage ancestor is found.
Implementation
static PageStorageBucket of(BuildContext context) {
final PageStorageBucket? bucket = maybeOf(context);
assert(() {
if (bucket == null) {
throw FlutterError(
'PageStorage.of() was called with a context that does not contain a '
'PageStorage widget.\n'
'No PageStorage widget ancestor could be found starting from the '
'context that was passed to PageStorage.of(). This can happen '
'because you are using a widget that looks for a PageStorage '
'ancestor, but no such ancestor exists.\n'
'The context used was:\n'
' $context',
);
}
return true;
}());
return bucket!;
}