- Flutter Widget Livebook


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


int _count = 0;

Widget build(BuildContext context) {
  return Column(
    mainAxisAlignment: MainAxisAlignment.center,
    children: <Widget>[
        duration: const Duration(milliseconds: 500),
        transitionBuilder: (Widget child, Animation<double> animation) {
          return ScaleTransition(child: child, scale: animation);
        child: Text(
          // 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,
        child: const Text('Increment'),
        onPressed: () {
          setState(() {
            _count += 1;

Related Links

  1. Example
  2. Related Links