of static method

RestorationBucket of(
  1. BuildContext context

Returns the RestorationBucket inserted into the widget tree by the closest ancestor RestorationScope of context.

To avoid accidentally overwriting data already stored in the bucket by its owner, data should not be stored directly in the bucket returned by this method. Instead, consider claiming a child bucket from the returned bucket (via RestorationBucket.claimChild) and store the restoration data in that child.

This method will assert in debug mode and throw an exception in release mode if state restoration is turned off for this subtree.

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

See also:


static RestorationBucket of(BuildContext context) {
  final RestorationBucket? bucket = maybeOf(context);
  assert(() {
    if (bucket == null) {
      throw FlutterError.fromParts(<DiagnosticsNode>[
          'RestorationScope.of() was called with a context that does not '
          'contain a RestorationScope widget. '
          'No RestorationScope widget ancestor could be found starting from '
          'the context that was passed to RestorationScope.of(). This can '
          'happen because you are using a widget that looks for a '
          'RestorationScope ancestor, but no such ancestor exists.\n'
          'The context used was:\n'
          '  $context'
          'State restoration must be enabled for a RestorationScope to exist. '
          'This can be done by passing a restorationScopeId to MaterialApp, '
          'CupertinoApp, or WidgetsApp at the root of the widget tree or by '
          'wrapping the widget tree in a RootRestorationScope.'
    return true;
  return bucket!;