AnimatedSwitcher

A widget that by default does a FadeTransition between a new widget and the widget previously set on the AnimatedSwitcher as a child.

Example

int _count = 0;


Widget build(BuildContext context) {
  return Column(
    mainAxisAlignment: MainAxisAlignment.center,
    children: <Widget>[
      AnimatedSwitcher(
        duration: const Duration(milliseconds: 500),
        transitionBuilder: (Widget child, Animation<double> animation) {
          return ScaleTransition(child: child, scale: animation);
        },
        child: Text(
          '$_count',
          // This key causes the AnimatedSwitcher to interpret this as a "new"
          // child each time the count changes, so that it will begin its animation
          // when the count changes.
          key: ValueKey<int>(_count),
          style: Theme.of(context).textTheme.display1,
        ),
      ),
      RaisedButton(
        child: const Text('Increment'),
        onPressed: () {
          setState(() {
            _count += 1;
          });
        },
      ),
    ],
  );
}

Related Links