I have created a BLoC using flutter_bloc, on which I listen to a stream. When the parent widget gets disposed (and therefore the BLoC object), I would like to close my stream.
class ChatBloc extends Bloc<ChatEvent, ChatState> {
//..bloc params..//
ChatBloc(this.chatId) {
this.add(MarkAsRead());
subscription = messagesFirestoreRepository.chatMessages(chatId).listen((messages) {
this.add(UpdateMessages(messages));
});
} //I WANT TO CLOSE THIS WHEN THE BLOC GETS DISPOSED OR DEINITED
//..other stuff..//
}
Does flutter_bloc or 'Any' class have the equivalent of dispose or Swift's deinit?
Thanks!