I am creating e-commerce app using MVVM architecture where I am using Stream Controller in ViewModel Class. When I change the orientation of my phone screen it says
Bad state: Stream has already been listened to
I have tried the adding the .broadcast When I initialize the stream controller
final StreamController _streamController = StreamController<ViewObject>.broadcast();
But still the output is not as desired instead the screen becomes blank.
To fix this issue, you can cancel the stream subscription when the ViewModel class is disposed. You can do this by overriding the dispose method in your ViewModel class and calling the cancel method on the stream subscription. Here is an example