无效状态:调用关闭后无法添加新事件

时间:2019-12-21 22:55:41

标签: flutter flutter-bloc

我有一个控制我页面的集团,当我按下图标时,我想将状态设置为初始状态,但是我遇到了错误状态:调用close之后无法添加新事件

这是我的集团代码

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(),

0 个答案:

没有答案