withAnimation<T> function
Animation
Applies an animation
to the state changes caused by calling block
.
To apply an animation only to state changes in a widget subtree, see Animated.
See AnimatingStateMixin for conveniently animating state changes in a StatefulWidget.
Returns the value returned by block
.
Only widgets that support animating with Fleet will animate changes. To implement support for this in your own widgets use AnimatableStatelessWidget or AnimatableSingleChildRenderObjectWidgetMixin.
The following provided widgets support animating with Fleet:
- FleetAlign
- FleetAspectRatio
- FleetCenter
- FleetColoredBox
- FleetColumn
- FleetConstrainedBox
- FleetContainer
- FleetDecoratedBox
- FleetFittedBox
- FleetFlex
- FractionalTranslation
- FleetFractionallySizedBox
- FleetLimitedBox
- FleetOpacity
- FleetOverflowBox
- FleetPadding
- FleetPositioned
- FleetPositionedDirectional
- FleetRow
- FleetSizedBox
- FleetSizedOverflowBox
- FleetSliverOpacity
- FleetSliverPadding
- FleetTransform
The following provided widgets are specific to Fleet:
Examples
import 'package:flutter/material.dart';
final active = ValueNotifier(false);
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
withAnimation(Curves.ease.animation(250.ms), () {
active.value = !active.value;
});
},
child: ValueListenableBuilder<bool>(
valueListenable: active,
builder: (context, active, _) {
return FleetColoredBox(color: active ? Colors.blue : Colors.grey);
},
),
);
}
}
See also:
- AnimatingStateMixin for conveniently animating state changes in a StatefulWidget.
- Animated for a widget that applies an
animation
to the state changes in its descendants.
Implementation
T withAnimation<T>(AnimationSpec animation, Block<T> block) {
return withTransaction(animation, block);
}