withAnimation<T> function Animation

T withAnimation<T>(
  1. AnimationSpec animation,
  2. Block<T> block
)

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:

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:

Implementation

T withAnimation<T>(AnimationSpec animation, Block<T> block) {
  return withTransaction(animation, block);
}