在Flutter中打开新屏幕后的上一个屏幕Bloc调用



我在我的项目中使用Bloc模式,但我以前屏幕的Bloc仍然在我的新屏幕中调用。我已经处理了我的Blob,但屏幕中的处理方法没有被调用。请帮助解决这个问题。

Blob文件:

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.

我想你需要在ui小部件中处理bloc,在那里你生成了bloc实例,而不是在bloc类本身中

相关内容

  • 没有找到相关文章

最新更新