pub struct SnapshotWidget {
pub key: Option<KeyRef>,
pub controller: Ref<SnapshotController>,
pub mode: SnapshotMode,
pub autoresize: bool,
pub painter: Option<SnapshotPainterRef>,
pub child: Option<WidgetRef>,
}Expand description
A widget that can replace its child with a snapshotted version of the child.
A snapshot is a frozen texture-backed representation of all child pictures
and layers stored as an Image.
This widget is useful for performing short animations that would otherwise be expensive or that cannot rely on raster caching. For example, scale and skew animations are often expensive to perform on complex children, as are blurs. For a short animation, a widget that contains these expensive effects can be replaced with a snapshot of itself and manipulated instead.
For example, the Android Q ZoomPageTransitionsBuilder uses a snapshot widget
for the forward and entering route to avoid the expensive scale animation.
This also has the effect of briefly pausing any animations on the page.
Generally, this widget should not be used in places where users expect the child widget to continue animating or to be responsive, such as an unbounded animation.
Caveats:
-
The contents of platform views cannot be captured by a snapshot widget. If a platform view is encountered, then the snapshot widget will determine how to render its children based on the
SnapshotMode. This defaults toSnapshotMode::Normalwhich will throw an exception if a platform view is encountered. -
On the CanvasKit backend of Flutter, the performance of using this widget may regress performance due to the fact that both the UI and engine share a single thread.
Fields§
§key: Option<KeyRef>See Widget::key.
controller: Ref<SnapshotController>The controller that determines when to display the children as a snapshot.
mode: SnapshotModeConfiguration that controls how the snapshot widget decides to paint its children.
Defaults to SnapshotMode::Normal, which throws an error when a platform view
or texture view is encountered.
See SnapshotMode for more information.
autoresize: boolWhether or not changes in render object size should automatically re-create the snapshot.
Defaults to false.
painter: Option<SnapshotPainterRef>The painter used to paint the child snapshot or child widgets.
None is Dart’s default, const _DefaultSnapshotPainter(): one painter per app,
reached through effective_painter, which paints the child
exactly as it would paint itself.
child: Option<WidgetRef>The widget below this widget in the tree.
Implementations§
Source§impl SnapshotWidget
impl SnapshotWidget
Sourcepub fn new(
controller: Ref<SnapshotController>,
child: Option<WidgetRef>,
) -> SnapshotWidget
pub fn new( controller: Ref<SnapshotController>, child: Option<WidgetRef>, ) -> SnapshotWidget
Create a new SnapshotWidget.
The controller and child arguments are required;
Dart’s child is required but nullable.
Sourcepub fn key(self, key: KeyRef) -> SnapshotWidget
pub fn key(self, key: KeyRef) -> SnapshotWidget
Dart SnapshotWidget(key:).
Sourcepub fn mode(self, mode: SnapshotMode) -> SnapshotWidget
pub fn mode(self, mode: SnapshotMode) -> SnapshotWidget
Dart SnapshotWidget(mode:).
Sourcepub fn painter(self, painter: SnapshotPainterRef) -> SnapshotWidget
pub fn painter(self, painter: SnapshotPainterRef) -> SnapshotWidget
Dart SnapshotWidget(painter:).
Sourcepub fn autoresize(self, autoresize: bool) -> SnapshotWidget
pub fn autoresize(self, autoresize: bool) -> SnapshotWidget
Dart SnapshotWidget(autoresize:).
Sourcepub fn effective_painter(&self, app: &mut App) -> SnapshotPainterRef
pub fn effective_painter(&self, app: &mut App) -> SnapshotPainterRef
Dart’s painter field: the given painter, or the app’s one default painter.
Trait Implementations§
Source§impl Debug for SnapshotWidget
impl Debug for SnapshotWidget
Source§impl RenderObjectWidget for SnapshotWidget
impl RenderObjectWidget for SnapshotWidget
Source§type RenderObject = RenderSnapshotWidget
type RenderObject = RenderSnapshotWidget
covariant RenderObject parameter type.Source§fn create_render_object(
&self,
app: &mut App,
context: BuildContext,
) -> AnyRenderObject
fn create_render_object( &self, app: &mut App, context: BuildContext, ) -> AnyRenderObject
RenderObject class that this widget represents, using the
configuration described by this widget. Read moreSource§fn update_render_object(
&self,
app: &mut App,
context: BuildContext,
render_object: RenderHandle<RenderSnapshotWidget>,
)
fn update_render_object( &self, app: &mut App, context: BuildContext, render_object: RenderHandle<RenderSnapshotWidget>, )
create_render_object. Read moreSource§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 to_string_short(&self) -> String
fn to_string_short(&self) -> String
toStringShort, for a widget that names itself apart from its type, as
SizedBox.expand does; see Widget::to_string_short.Source§fn debug_visit_onstage_children(
&self,
app: &App,
children: &[AnyElement],
visitor: &mut dyn FnMut(AnyElement),
)
fn debug_visit_onstage_children( &self, app: &App, children: &[AnyElement], visitor: &mut dyn FnMut(AnyElement), )
debugVisitOnstageChildren of the element this widget makes, for a widget whose
Dart element subclass overrides it only to hide children (_OffstageElement,
_IndexedStackElement): calls visitor for each of children, in order, that is
onstage. Waft’s generic single- and multi-child elements stand in for those subclasses
and ask their widget here; an element of a widget’s own overrides
Element::debug_visit_onstage_children instead.Source§fn did_unmount_render_object(
&self,
app: &mut App,
render_object: RenderHandle<Self::RenderObject>,
)
fn did_unmount_render_object( &self, app: &mut App, render_object: RenderHandle<Self::RenderObject>, )
RenderObject will be of the same type as returned by this object’s
create_render_object.Auto Trait Implementations§
impl !RefUnwindSafe for SnapshotWidget
impl !Send for SnapshotWidget
impl !Sync for SnapshotWidget
impl !UnwindSafe for SnapshotWidget
impl Forget for SnapshotWidget
impl Freeze for SnapshotWidgetwhere
*const RcInner<dyn Key> is !null: Freeze,
PhantomData<RcInner<dyn Key>>: Freeze,
NonZero<u32>: Freeze,
PhantomData<fn() -> SnapshotController>: Freeze,
*const RcInner<Keep> is !null: Freeze,
PhantomData<RcInner<Keep>>: Freeze,
&'static SnapshotPainterVTable: Freeze,
*const RcInner<dyn Widget> is !null: Freeze,
PhantomData<RcInner<dyn Widget>>: Freeze,
impl Move for SnapshotWidget
impl Unpin for SnapshotWidget
impl UnsafeUnpin for SnapshotWidgetwhere
*const RcInner<dyn Key> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Key>>: UnsafeUnpin,
NonZeroU32Inner: UnsafeUnpin,
PhantomData<fn() -> SnapshotController>: UnsafeUnpin,
*const RcInner<Keep> is !null: UnsafeUnpin,
PhantomData<RcInner<Keep>>: UnsafeUnpin,
&'static SnapshotPainterVTable: UnsafeUnpin,
*const RcInner<dyn Widget> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Widget>>: 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<SingleChildRenderObjectKind> for Wwhere
W: SingleChildRenderObjectWidget,
<W as RenderObjectWidget>::RenderObject: RenderObjectWithChildMixin,
impl<W> IntoWidget<SingleChildRenderObjectKind> for Wwhere
W: SingleChildRenderObjectWidget,
<W as RenderObjectWidget>::RenderObject: RenderObjectWithChildMixin,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.