I am using Bloc pattern in my project, But my previous screen's Bloc still call in my new screen. I have dispose my Bloc but in screen dispose method is not call. Please help to solve this problem.
Bloc file:
class ForgotPasswordBloc extends Object {
final PublishSubject<ForgotPassState> _passStateSubject = new PublishSubject();
Stream<ForgotPassState> get passStateStream => _passStateSubject.stream;
void changeState({ForgotPassState state}) => _passStateSubject.sink.add(state);
forgotPasswordSubmit(String email) async {
changeState(state: ForgotPassState(status: ForgotPassStatus.CALLING, message: "calling"));
var response = await post(Constant.API_URL+"forgotPassword", body: {
"email": email,
});
ForgotPasswordModal data = ForgotPasswordModal.fromJson(json.decode(response.body));
if (data.status == "success") {
await changeState(state: ForgotPassState(status: ForgotPassStatus.SUCCESS, message: "Success"));
} else {
changeState(
state: ForgotPassState(
status: ForgotPassStatus.ERROR, message: data.message));
}
}
dispose() {
print("dispose called==========>");
_passStateSubject.close();
}
}
Here I call the bloc method:
StreamBuilder<ForgotPassState>(
stream: forgotpass_bloc.passStateStream,
builder: (context, AsyncSnapshot<ForgotPassState> snapshot) {
switch (snapshot.data.status) {
case ForgotPassStatus.SUCCESS:
WidgetsBinding.instance.addPostFrameCallback((_) => showInformationDialog(context,email_controller.text.trim()));
break;
default:
return Container();
}
},
),
In above code after getting success response my information dialog is open, In dialog I have close button After click on the close button I have open new Screen but in that screen my previous screen dialog is display.