1

我有控制我的页面的块,当按下图标时我想将状态设置为初始状态,但我得到了错误状态:调用关闭后无法添加新事件

这是我的集团代码

class ForgotPasswordBloc
    extends Bloc<ForgotPasswordEvent, ForgotPasswordState> {
  UserRepository _userRepository = UserRepository();

  @override
  ForgotPasswordState get initialState => ForgotPasswordInitial();

  @override
  Stream<ForgotPasswordState> mapEventToState(
      ForgotPasswordEvent event) async* {
    if (event is RequestOTP) {
      yield ForgotPasswordInitialLoading();

      try {
        bool result = await _userRepository.requestOtp(
            forgotPasswordCredentials:
                ForgotPasswordCredentials(noHp: event.noHp));

        if (!result)
          yield ForgotPasswordInitialFailure(error: "Phone number is invalid");
        else
          yield ForgotPasswordOTP();
      } catch (e) {
        yield ForgotPasswordInitialFailure(error: e.toString());
      }
    }

    if (event is BackToLoginInitial) {
      print("msk sini");
      yield ForgotPasswordInitialLoading();
    }
  }
}

这是我的页面,按钮返回

state is ForgotPasswordOTP
                          ? Positioned(
                              top: 66,
                              left: 0,
                              child: Container(
                                alignment: Alignment.centerLeft,
                                child: IconButton(
                                    icon: Icon(
                                      Icons.arrow_back,
                                      color: Colors.white,
                                    ),
                                    iconSize: 30,
                                    onPressed: () {
                                      // if (state is ForgotPasswordOTP)
                                      forgotPasswordBloc
                                          .add(BackToLoginInitial());
                                    }),
                              ),
                            )
                          : Container(),
4

0 回答 0