Skip to main content

RestorationScope

Struct RestorationScope 

Source
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:

Fields§

§key: Option<KeyRef>§child: WidgetRef

The 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

Source

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.

Source

pub fn key(self, key: KeyRef) -> RestorationScope

Dart RestorationScope(key:).

Source

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:

Source

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:

Trait Implementations§

Source§

impl Debug for RestorationScope

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl StatefulWidget for RestorationScope

Source§

type State = RestorationScopeState

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn create_state(&self) -> RestorationScopeState

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s 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 debug_check_constructor(&self)

Source§

fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>

Source§

fn type_name(&self) -> &'static str

See 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
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const RcInner<dyn Widget> is !null: Freeze, PhantomData<RcInner<dyn Widget>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for RestorationScope

§

impl Unpin for RestorationScope
where Rc<dyn Key>: Unpin, Rc<dyn Widget>: Unpin, *const u8 is !null: Unpin,

§

impl UnsafeUnpin for RestorationScope
where *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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<W> IntoWidget<StatefulKind> for W
where W: StatefulWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>