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?