crossFade method

Widget crossFade({
  1. required Key key,
  2. Duration duration = const Duration(milliseconds: 300),
  3. Curve switchInCurve = Curves.easeIn,
  4. Curve switchOutCurve = Curves.easeOut,
})

Wraps the widget for animated switching with cross-fade.

Example:

showFirst
  ? Text('First').crossFade(key: ValueKey('first'))
  : Text('Second').crossFade(key: ValueKey('second'));

Implementation

Widget crossFade({
  required Key key,
  Duration duration = const Duration(milliseconds: 300),
  Curve switchInCurve = Curves.easeIn,
  Curve switchOutCurve = Curves.easeOut,
}) {
  return AnimatedSwitcher(
    duration: duration,
    switchInCurve: switchInCurve,
    switchOutCurve: switchOutCurve,
    child: KeyedSubtree(
      key: key,
      child: this,
    ),
  );
}