Posts

Showing posts from March, 2019

Flutter - BLoC pattern - How to use streams to invoke a method of another widget, i.e. an animation?

Image
1 1 Suppose there is a widget with a method controlling visibility animation, toggleVisibility() . In a BLoC pattern, I want to use a stream to invoke that function. I find this pretty tricky. Since it is an animation rather than a complete redraw, a StreamBuilder doesn't fit. Manually add a listener to the BLoC streams isn't convenient either. In initeState() function of the target widget, we don't have a context, so it's hard to get a reference to the BLoC. Edit: This is not the case after I read Rémi Rousselet's answer. We can access the context even outside of build() function, because State<T> class has a property named 'context' and is documented in Flutter's docs.... I wasn't aware of that. In build(context) function of the target widget, we have the