How to animate widget generated by StreamBuilder?
Your BlocBuilder
should wrap the AnimatedSwitcher
and not the opposite.
The animation of AnimatedSwitcher
happens when its direct child change. But in your case, the direct child is always BlocBuilder
.
StreamBuilder(
stream: stream,
builder: (context, snapshot) {
return AnimatedSwitcher(
duration: const Duration(seconds: 4),
child: snapshot.hasData
? Text(snapshot.data)
: CircularProgressIndicator();
);
}
),
You could try with AnimatedCrossFade It accepts 2 children, duration and state (AnimatedCrossFadeState.showFirst and AnimatedCrossFadeState.showSecond) and it will animate fade between two children.
documentation: https://docs.flutter.io/flutter/widgets/AnimatedCrossFade-class.html