pub struct AnimatedSwitcher {
pub key: Option<KeyRef>,
pub child: Option<WidgetRef>,
pub duration: Duration,
pub reverse_duration: Option<Duration>,
pub switch_in_curve: Rc<dyn Curve>,
pub switch_out_curve: Rc<dyn Curve>,
pub transition_builder: AnimatedSwitcherTransitionBuilder,
pub layout_builder: AnimatedSwitcherLayoutBuilder,
}Expand description
A widget that by default does a cross-fade between a new widget and the
widget previously set on the AnimatedSwitcher as a child.
If they are swapped fast enough (i.e. before duration elapses), more
than one previous child can exist and be transitioning out while the newest one is
transitioning in.
If the “new” child is the same widget type and key as the “old” child, but
with different parameters, then AnimatedSwitcher will not do a
transition between them, since as far as the framework is concerned, they
are the same widget and the existing widget can be updated with the new
parameters. To force the transition to occur, set a key on each child
widget that you wish to be considered unique (typically a ValueKey on the
widget data that distinguishes this child from the others).
The same key can be used for a new child as was used for an already-outgoing child; the two will not be considered related. (For example, if a progress indicator with key A is first shown, then an image with key B, then another progress indicator with key A again, all in rapid succession, then the old progress indicator and the image will be fading out while a new progress indicator is fading in.)
The type of transition can be changed from a cross-fade to a custom
transition by setting the transition_builder.
See also:
AnimatedCrossFade, which only fades between two children, but also interpolates their sizes, and is reversible.AnimatedOpacity, which can be used to switch between nothingness and a given child by fading the child in and out.FadeTransition, whichAnimatedSwitcheruses to perform the transition.
Fields§
§key: Option<KeyRef>§child: Option<WidgetRef>The current child widget to display. If there was a previous child, then
that child will be faded out using the switch_out_curve,
while the new child is faded in with the switch_in_curve,
over the duration.
If there was no previous child, then this child will fade in using the
switch_in_curve over the duration.
The child is considered to be “new” if it has a different type or key
(see Widget.canUpdate).
To change the kind of transition used, see
transition_builder.
duration: DurationThe duration of the transition from the old child value to the new
one.
This duration is applied to the given child when that property is set
to a new child. The same duration is used when fading out, unless
reverse_duration is set. Changing
duration will not affect the durations of transitions already in
progress.
reverse_duration: Option<Duration>The duration of the transition from the new child value to the old
one.
This duration is applied to the given child when that property is set
to a new child. Changing reverse_duration will not affect
the durations of transitions already in progress.
If not set, then the value of duration is used by default.
switch_in_curve: Rc<dyn Curve>The animation curve to use when transitioning in a new child.
This curve is applied to the given child when that property is set to
a new child. Changing switch_in_curve will not affect the
curve of a transition already in progress.
The switch_out_curve is used when fading out, except that
if child is changed while the current child is in the middle of
fading in, switch_in_curve will be run in reverse from that
point instead of jumping to the corresponding point on
switch_out_curve.
switch_out_curve: Rc<dyn Curve>The animation curve to use when transitioning a previous child out.
This curve is applied to the child when the child is faded in (or
when the widget is created, for the first child). Changing
switch_out_curve will not affect the curves of
already-visible widgets, it only affects the curves of future children.
If child is changed while the current child is in the middle of
fading in, switch_in_curve will be run in reverse from that
point instead of jumping to the corresponding point on
switch_out_curve.
transition_builder: AnimatedSwitcherTransitionBuilderA function that wraps a new child with an animation that transitions
the child in when the animation runs in the forward direction and out
when the animation runs in the reverse direction. This is only called
when a new child is set (not for each build), or when a new
transition_builder is set. If a new
transition_builder is set, then the transition is
rebuilt for the current child and all previous children using the new
transition_builder.
The default is AnimatedSwitcher::default_transition_builder.
The animation provided to the builder has the duration and
switch_in_curve or
switch_out_curve applied as provided when the
corresponding child was first provided.
See also:
AnimatedSwitcherTransitionBuilderfor more information about how a transition builder should function.
layout_builder: AnimatedSwitcherLayoutBuilderA function that wraps all of the children that are transitioning out, and
the child that’s transitioning in, with a widget that lays all of them
out. This is called every time this widget is built.
The default is AnimatedSwitcher::default_layout_builder.
See also:
AnimatedSwitcherLayoutBuilderfor more information about how a layout builder should function.
Implementations§
Source§impl AnimatedSwitcher
impl AnimatedSwitcher
Sourcepub fn new(duration: Duration) -> AnimatedSwitcher
pub fn new(duration: Duration) -> AnimatedSwitcher
Creates an AnimatedSwitcher.
Sourcepub fn key(self, key: KeyRef) -> AnimatedSwitcher
pub fn key(self, key: KeyRef) -> AnimatedSwitcher
Dart AnimatedSwitcher(key:).
Sourcepub fn child<K>(self, child: impl IntoWidget<K>) -> AnimatedSwitcher
pub fn child<K>(self, child: impl IntoWidget<K>) -> AnimatedSwitcher
Dart AnimatedSwitcher(child:).
Sourcepub fn reverse_duration(self, reverse_duration: Duration) -> AnimatedSwitcher
pub fn reverse_duration(self, reverse_duration: Duration) -> AnimatedSwitcher
Dart AnimatedSwitcher(reverseDuration:).
Sourcepub fn switch_in_curve(self, switch_in_curve: Rc<dyn Curve>) -> AnimatedSwitcher
pub fn switch_in_curve(self, switch_in_curve: Rc<dyn Curve>) -> AnimatedSwitcher
Dart AnimatedSwitcher(switchInCurve:).
Sourcepub fn switch_out_curve(
self,
switch_out_curve: Rc<dyn Curve>,
) -> AnimatedSwitcher
pub fn switch_out_curve( self, switch_out_curve: Rc<dyn Curve>, ) -> AnimatedSwitcher
Dart AnimatedSwitcher(switchOutCurve:).
Sourcepub fn transition_builder(
self,
transition_builder: AnimatedSwitcherTransitionBuilder,
) -> AnimatedSwitcher
pub fn transition_builder( self, transition_builder: AnimatedSwitcherTransitionBuilder, ) -> AnimatedSwitcher
Dart AnimatedSwitcher(transitionBuilder:).
Sourcepub fn layout_builder(
self,
layout_builder: impl Fn(&mut App, Option<&WidgetRef>, &[WidgetRef]) -> WidgetRef + 'static,
) -> AnimatedSwitcher
pub fn layout_builder( self, layout_builder: impl Fn(&mut App, Option<&WidgetRef>, &[WidgetRef]) -> WidgetRef + 'static, ) -> AnimatedSwitcher
Dart AnimatedSwitcher(layoutBuilder:).
Sourcepub fn default_transition_builder(
_app: &mut App,
child: &WidgetRef,
animation: AnimationRef<f64>,
) -> WidgetRef
pub fn default_transition_builder( _app: &mut App, child: &WidgetRef, animation: AnimationRef<f64>, ) -> WidgetRef
The transition builder used as the default value of
transition_builder.
The new child is given a FadeTransition which increases opacity as
the animation goes from 0.0 to 1.0, and decreases when the animation is
reversed.
This is an AnimatedSwitcherTransitionBuilder function.
Sourcepub fn default_layout_builder(
_app: &mut App,
current_child: Option<&WidgetRef>,
previous_children: &[WidgetRef],
) -> WidgetRef
pub fn default_layout_builder( _app: &mut App, current_child: Option<&WidgetRef>, previous_children: &[WidgetRef], ) -> WidgetRef
The layout builder used as the default value of
layout_builder.
The new child is placed in a Stack that sizes itself to match the
largest of the child or a previous child. The children are centered on
each other.
This is an AnimatedSwitcherLayoutBuilder function.
Trait Implementations§
Source§impl Debug for AnimatedSwitcher
impl Debug for AnimatedSwitcher
Source§impl StatefulWidget for AnimatedSwitcher
impl StatefulWidget for AnimatedSwitcher
Source§type State = AnimatedSwitcherState
type State = AnimatedSwitcherState
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 create_state(&self) -> AnimatedSwitcherState
fn create_state(&self) -> AnimatedSwitcherState
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 AnimatedSwitcher
impl !Send for AnimatedSwitcher
impl !Sync for AnimatedSwitcher
impl !UnwindSafe for AnimatedSwitcher
impl Forget for AnimatedSwitcher
impl Freeze for AnimatedSwitcherwhere
*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>, Retained<AnyAnimation<f64>>) -> Rc<dyn Widget>> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App, &Rc<dyn Widget>, Retained<AnyAnimation<f64>>) -> Rc<dyn Widget>>>: Freeze,
*const (): Freeze,
NonZero<u32>: Freeze,
*const RcInner<dyn Fn(&mut App, Option<&Rc<dyn Widget>>, &[Rc<dyn Widget>]) -> Rc<dyn Widget>> is !null: Freeze,
PhantomData<RcInner<dyn Fn(&mut App, Option<&Rc<dyn Widget>>, &[Rc<dyn Widget>]) -> Rc<dyn Widget>>>: Freeze,
impl Move for AnimatedSwitcher
impl Unpin for AnimatedSwitcher
impl UnsafeUnpin for AnimatedSwitcherwhere
*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>, Retained<AnyAnimation<f64>>) -> Rc<dyn Widget>> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App, &Rc<dyn Widget>, Retained<AnyAnimation<f64>>) -> Rc<dyn Widget>>>: UnsafeUnpin,
*const (): UnsafeUnpin,
NonZeroU32Inner: UnsafeUnpin,
*const RcInner<dyn Fn(&mut App, Option<&Rc<dyn Widget>>, &[Rc<dyn Widget>]) -> Rc<dyn Widget>> is !null: UnsafeUnpin,
PhantomData<RcInner<dyn Fn(&mut App, Option<&Rc<dyn Widget>>, &[Rc<dyn Widget>]) -> Rc<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<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.