问题描述
在登录视图中,如果用户在未插入其凭据的情况下点击登录按钮,则LoginFailState为yield,并且视图对此做出反应.如果他再次点击,则此LoginFailstate再次变为yield,但是视图对此没有反应.那么,有没有办法产生相同状态下更多的时间?
In the login view, if the user taps on the login button without having inserted his credentials, the LoginFailState is yield and the view reacts to it. If he taps again, this LoginFailstate is yield again, but the view doesn't react to it. So, is there a way to yield more times the same state?
有一些代码可以更好地解释我的情况:
There is some code to better explain my situation:
class LoginBloc extends Bloc<LoginEvent, LoginState> {
@override
LoginState get initialState => LoginUninitialized();
@override
Stream<LoginState> mapEventToState(LoginEvent event) {
if (event is loginButtonPressed) {
yield LoginFailState();
}
}
查看:
@override
Widget build(BuildContext context) {
return BlocBuilder(
bloc: _loginBloc,
builder: (BuildContext context, LoginState state) {
if (state is LoginFail) {
print ('Login fail');
}
return Column(
...
)
推荐答案
如果您不扩展Equitable,或者实现使两个LoginFailStates成为自己的'=='逻辑,则可以收到相同"状态的更新.平等的.
You can receive an update for the "same" State if you don't extend Equitable, or implement your own '==' logic which makes the two LoginFailStates equal.
解决方案是在两者之间产生不同的状态,就像在Bloc示例中一样.
The solution is to yield a different State in between, like in the Bloc example.
yield LoginLoading();
每次登录按钮被点击时都会调用它. Felangel的LoginBloc示例.
It gets called on every login button tap. Felangel's LoginBloc example.
这篇关于Bloc:是否可能产生相同状态的2倍?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!