0

I do floating alert which is controlled with stream. The logic of that alert is, when tap the OK button on it to turn true to stream and then close.

I will show my codes, and please fix me what my logic wrong.

 Widget dataState(
      AsyncSnapshot pinValidateSnapshot, ChangePinBloc changePinBloc) {
    if (pinValidateSnapshot.data == true) {
      WidgetsBinding.instance.addPostFrameCallback(
          (_) => Navigator.pushNamed(context, newConfirmPinRoute));
    }
    else if(pinValidateSnapshot.data == false){
      return StreamBuilder(
        stream: changePinBloc.alertStream,
        builder: (context, AsyncSnapshot<bool> alertSnapshot) {
          // if (alertSnapshot.hasError) {
          //   changePinBloc.onCloseAlert(false);
          // }
          return Positioned.fill(
            child: Visibility(
              visible: alertSnapshot.data != true,
              child: AlertContainerView(
                message: 'Same',
                onOKTap: () {
                  changePinBloc.onCloseAlert(true);
                },
              ),
            ),
          );
        },
      );
    }
    return Center(child: Text('WTF'),);
  }

Here is codes in bloc class

final alertController = PublishSubject<bool>();
Stream<bool>get alertStream => alertController.stream;

  void onCloseAlert(bool flag) {
    alertController.sink.add(flag);

  }

In here although pinValidateSnapshot change state, the alertSnapshot don't change start again from initial state, it always left previous state and alert not show again. How to do with that?

Ken White
  • 123,280
  • 14
  • 225
  • 444
La Pyae
  • 371
  • 3
  • 19
  • provide the whole code so that it can replicated. There are already few lines that I really don't understand why you have them there... so... – HW Kim Jan 12 '23 at 13:02

0 Answers0