pub struct RestorationScope {
pub key: Option<KeyRef>,
pub child: WidgetRef,
pub restoration_id: Option<String>,
}Expand description
Creates a new scope for restoration IDs used by descendant widgets to claim
RestorationBuckets.
A restoration scope inserts a RestorationBucket into the widget tree, which descendant
widgets can access via RestorationScope::of. It is uncommon for descendants to directly
store data in this bucket. Instead, descendant widgets should consider storing their own
restoration data in a child bucket claimed with RestorationBucket::claim_child from the
bucket provided by this scope.
The bucket inserted into the widget tree by this scope has been claimed from the
surrounding RestorationScope using the provided
restoration_id. If the RestorationScope is moved to a
different part of the widget tree under a different RestorationScope, the bucket owned
by this scope with all its children and the data contained in them is moved to the new
scope as well.
This widget will not make a RestorationBucket available to descendants if
restoration_id is None or when there is no surrounding
restoration scope to claim a bucket from. In this case, descendant widgets invoking
RestorationScope::of will receive None as a return value indicating that no bucket is
available for storing restoration data. This will turn off state restoration for the widget
subtree.
See also:
RootRestorationScope, which inserts the root bucket provided by theRestorationManagerinto the widget tree and makes it accessible for descendants viaRestorationScope::of.UnmanagedRestorationScope, which inserts a providedRestorationBucketinto the widget tree and makes it accessible for descendants viaRestorationScope::of.RestorationMixin, which may be used inStateobjects to manage the restoration data of aStatefulWidgetinstead of manually interacting withRestorationScopes andRestorationBuckets.RestorationManager, which describes the basic concepts of state restoration.
Fields§
§key: Option<KeyRef>See StatefulWidget::key.
child: WidgetRefThe widget below this widget in the tree.
restoration_id: Option<String>The restoration ID used by this widget to obtain a child bucket from the surrounding
RestorationScope.
The child bucket obtained from the surrounding scope is made available to descendant
widgets via RestorationScope::of.
If this is None, RestorationScope::of invoked by descendants will return None,
which effectively turns off state restoration for this subtree.
Implementations§
Source§impl RestorationScope
impl RestorationScope
Sourcepub fn new<K>(
restoration_id: Option<String>,
child: impl IntoWidget<K>,
) -> RestorationScope
pub fn new<K>( restoration_id: Option<String>, child: impl IntoWidget<K>, ) -> RestorationScope
Creates a RestorationScope.
Providing None as the restoration_id turns off state restoration for the child
and its descendants.
Sourcepub fn key(self, key: KeyRef) -> RestorationScope
pub fn key(self, key: KeyRef) -> RestorationScope
Dart RestorationScope(key:).
Sourcepub fn maybe_of(
app: &mut App,
context: BuildContext,
) -> Option<Handle<RestorationBucket>>
pub fn maybe_of( app: &mut App, context: BuildContext, ) -> Option<Handle<RestorationBucket>>
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::claim_child) and store the restoration data in that child.
This method returns None if state restoration is turned off for this subtree.
Calling this method will create a dependency on the closest RestorationScope in the
context, if there is one.
See also:
RestorationScope::of, which is similar to this method, but panics if noRestorationScopeancestor is found.
Sourcepub fn of(app: &mut App, context: BuildContext) -> Handle<RestorationBucket>
pub fn of(app: &mut App, context: BuildContext) -> Handle<RestorationBucket>
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::claim_child) and store the restoration data in that child.
This method panics 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:
RestorationScope::maybe_of, which is similar to this method, but returnsNoneif noRestorationScopeancestor is found.
Trait Implementations§
Source§impl Debug for RestorationScope
impl Debug for RestorationScope
Source§impl StatefulWidget for RestorationScope
impl StatefulWidget for RestorationScope
Source§type State = RestorationScopeState
type State = RestorationScopeState
Source§fn create_state(&self) -> RestorationScopeState
fn create_state(&self) -> RestorationScopeState
Source§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
debugFillProperties: the properties a dump shows for this widget, in Dart’s
order. Dart’s Widget base only sets the dense tree style, which the framework does.Source§fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Widget::type_name. A stateful form another widget kind becomes (an animated or
status transition widget) names the widget it wraps.Auto Trait Implementations§
impl !RefUnwindSafe for RestorationScope
impl !Send for RestorationScope
impl !Sync for RestorationScope
impl !UnwindSafe for RestorationScope
impl Forget for RestorationScope
impl Freeze for RestorationScope
impl Move for RestorationScope
impl Unpin for RestorationScope
impl UnsafeUnpin for RestorationScopewhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
*const RcInner<dyn Widget> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Widget>>: UnsafeUnpin,
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.