Skip to main content

AnimatedCrossFade

Struct AnimatedCrossFade 

Source
pub struct AnimatedCrossFade {
Show 14 fields pub key: Option<KeyRef>, pub first_child: WidgetRef, pub second_child: WidgetRef, pub cross_fade_state: CrossFadeState, pub duration: Duration, pub reverse_duration: Option<Duration>, pub first_curve: Rc<dyn Curve>, pub second_curve: Rc<dyn Curve>, pub size_curve: Rc<dyn Curve>, pub alignment: AlignmentGeometry, pub layout_builder: AnimatedCrossFadeBuilder, pub exclude_bottom_focus: bool, pub clip_behavior: Clip, pub on_end: Option<Listener>,
}
Expand description

A widget that cross-fades between two given children and animates itself between their sizes.

The animation is controlled through the cross_fade_state parameter. first_curve and second_curve represent the opacity curves of the two children. The first_curve is inverted, i.e. it fades out when providing a growing curve like Curves::linear. The size_curve is the curve used to animate between the size of the fading-out child and the size of the fading-in child.

This widget is intended to be used to fade a pair of widgets with the same width. In the case where the two children have different heights, the animation crops overflowing children during the animation by aligning their top edge, which means that the bottom will be clipped.

The animation is automatically triggered when an existing AnimatedCrossFade is rebuilt with a different value for the cross_fade_state property.

See also:

  • AnimatedOpacity, which fades between nothing and a single child.
  • AnimatedSwitcher, which switches out a child for a new one with a customizable transition, supporting multiple cross-fades at once.
  • AnimatedSize, the lower-level widget which AnimatedCrossFade uses to automatically change size.

Fields§

§key: Option<KeyRef>§first_child: WidgetRef

The child that is visible when cross_fade_state is CrossFadeState::ShowFirst. It fades out when transitioning cross_fade_state from CrossFadeState::ShowFirst to CrossFadeState::ShowSecond and vice versa.

§second_child: WidgetRef

The child that is visible when cross_fade_state is CrossFadeState::ShowSecond. It fades in when transitioning cross_fade_state from CrossFadeState::ShowFirst to CrossFadeState::ShowSecond and vice versa.

§cross_fade_state: CrossFadeState

The child that will be shown when the animation has completed.

§duration: Duration

The duration of the whole orchestrated animation.

§reverse_duration: Option<Duration>

The duration of the whole orchestrated animation when running in reverse.

If not supplied, this defaults to duration.

§first_curve: Rc<dyn Curve>

The fade curve of the first child.

Defaults to Curves::linear.

§second_curve: Rc<dyn Curve>

The fade curve of the second child.

Defaults to Curves::linear.

§size_curve: Rc<dyn Curve>

The curve of the animation between the two children’s sizes.

Defaults to Curves::linear.

§alignment: AlignmentGeometry

How the children should be aligned while the size is animating.

Defaults to Alignment::TOP_CENTER.

See also:

  • Alignment, a class with convenient constants typically used to specify an AlignmentGeometry.
  • AlignmentDirectional, like Alignment for specifying alignments relative to text direction.
§layout_builder: AnimatedCrossFadeBuilder

A builder that positions the first_child and second_child widgets.

The widget returned by this method is wrapped in an AnimatedSize.

By default, this uses AnimatedCrossFade::default_layout_builder, which uses a Stack and aligns the bottom_child to the top of the stack while providing the top_child as the non-positioned child to fill the provided constraints. This works well when the AnimatedCrossFade is in a position to change size and when the children are not flexible. However, if the children are less fussy about their sizes (for example a CircularProgressIndicator inside a Center), or if the AnimatedCrossFade is being forced to a particular size, then it can result in the widgets jumping about when the cross-fade state is changed.

§exclude_bottom_focus: bool

When true, this is equivalent to wrapping the bottom widget with an ExcludeFocus widget while it is at the bottom of the cross-fade stack.

Defaults to true. When it is false, the bottom widget in the cross-fade stack can remain in focus until the top widget requests focus. This is useful for animating between different TextFields so the keyboard remains open during the cross-fade animation.

§clip_behavior: Clip

Controls whether the content is clipped during the cross-fade transition.

During the size transition between first_child and second_child, the content is clipped by default to prevent it from overflowing the bounding box of the animating widget.

Set this to Clip::None to disable clipping entirely. This can be useful for widgets with shadows or visual effects that extend beyond their bounds.

Defaults to Clip::HardEdge.

§on_end: Option<Listener>

Called every time an animation completes.

This can be useful to trigger additional actions (e.g. another animation) at the end of the current animation.

Implementations§

Source§

impl AnimatedCrossFade

Source

pub fn new<F, S>( first_child: impl IntoWidget<F>, second_child: impl IntoWidget<S>, cross_fade_state: CrossFadeState, duration: Duration, ) -> AnimatedCrossFade

Creates a cross-fade animation widget.

The duration of the animation is the same for all components (fade in, fade out, and size), and you can pass Intervals instead of Curves in order to have finer control, e.g., creating an overlap between the fades.

Source

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

Dart AnimatedCrossFade(key:).

Source

pub fn reverse_duration(self, reverse_duration: Duration) -> AnimatedCrossFade

Dart AnimatedCrossFade(reverseDuration:).

Source

pub fn first_curve(self, first_curve: Rc<dyn Curve>) -> AnimatedCrossFade

Dart AnimatedCrossFade(firstCurve:).

Source

pub fn second_curve(self, second_curve: Rc<dyn Curve>) -> AnimatedCrossFade

Dart AnimatedCrossFade(secondCurve:).

Source

pub fn size_curve(self, size_curve: Rc<dyn Curve>) -> AnimatedCrossFade

Dart AnimatedCrossFade(sizeCurve:).

Source

pub fn alignment(self, alignment: AlignmentGeometry) -> AnimatedCrossFade

Dart AnimatedCrossFade(alignment:).

Source

pub fn layout_builder( self, layout_builder: impl Fn(&mut App, &WidgetRef, &KeyRef, &WidgetRef, &KeyRef) -> WidgetRef + 'static, ) -> AnimatedCrossFade

Dart AnimatedCrossFade(layoutBuilder:).

Source

pub fn exclude_bottom_focus( self, exclude_bottom_focus: bool, ) -> AnimatedCrossFade

Dart AnimatedCrossFade(excludeBottomFocus:).

Source

pub fn clip_behavior(self, clip_behavior: Clip) -> AnimatedCrossFade

Dart AnimatedCrossFade(clipBehavior:).

Source

pub fn on_end(self, on_end: Listener) -> AnimatedCrossFade

Dart AnimatedCrossFade(onEnd:).

Source

pub fn default_layout_builder( _app: &mut App, top_child: &WidgetRef, top_child_key: &KeyRef, bottom_child: &WidgetRef, bottom_child_key: &KeyRef, ) -> WidgetRef

The default layout algorithm used by AnimatedCrossFade.

The top child is placed in a stack that sizes itself to match the top child. The bottom child is positioned at the top of the same stack, sized to fit its width but without forcing the height. The stack is then clipped.

This is the default value for layout_builder. It implements AnimatedCrossFadeBuilder.

Trait Implementations§

Source§

impl Debug for AnimatedCrossFade

Source§

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

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

impl StatefulWidget for AnimatedCrossFade

Source§

type State = AnimatedCrossFadeState

The state this widget creates.
Source§

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

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 create_state(&self) -> AnimatedCrossFadeState

Creates the mutable state for this widget at a given location in the tree. Read more
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 AnimatedCrossFade

§

impl !Send for AnimatedCrossFade

§

impl !Sync for AnimatedCrossFade

§

impl !UnwindSafe for AnimatedCrossFade

§

impl Forget for AnimatedCrossFade

§

impl Freeze for AnimatedCrossFade
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 RcInner<dyn Curve> is !null: Freeze, PhantomData<RcInner<dyn Curve>>: Freeze, *const RcInner<dyn Fn(&mut App, &Rc<dyn Widget>, &KeyRef, &Rc<dyn Widget>, &KeyRef) -> Rc<dyn Widget>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, &Rc<dyn Widget>, &KeyRef, &Rc<dyn Widget>, &KeyRef) -> Rc<dyn Widget>>>: Freeze, *const RcInner<dyn Fn(&mut App)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App)>>: Freeze, NonZero<u32>: Freeze, *const (): Freeze,

§

impl Move for AnimatedCrossFade

§

impl Unpin for AnimatedCrossFade
where Rc<dyn Key>: Unpin, Rc<dyn Widget>: Unpin, Rc<dyn Curve>: Unpin, Rc<dyn Fn(&mut App, &Rc<dyn Widget>, &KeyRef, &Rc<dyn Widget>, &KeyRef) -> Rc<dyn Widget>>: Unpin, Rc<dyn Fn(&mut App)>: Unpin, NonZero<u32>: Unpin, *const (): Unpin,

§

impl UnsafeUnpin for AnimatedCrossFade
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 RcInner<dyn Curve> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Curve>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, &Rc<dyn Widget>, &KeyRef, &Rc<dyn Widget>, &KeyRef) -> Rc<dyn Widget>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, &Rc<dyn Widget>, &KeyRef, &Rc<dyn Widget>, &KeyRef) -> Rc<dyn Widget>>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App)>>: UnsafeUnpin, NonZeroU32Inner: UnsafeUnpin, *const (): 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>