Event dispatched hit the Bloc once and no more
nguyenhuutinh opened this issue · comments
TN commented
Hi,
I tried your template.
It's ok but when I reopen the page and dispatch with new param . it not reload.
Do you know why
@override
void initState() {
super.initState();
this._loginBloc.dispatch(LoadLoginEvent(Random().nextInt(1000)));
}
@override
void dispose() {
super.dispose();
this._loginBloc.dispose();
}
@immutable
abstract class LoginEvent extends Equatable{
LoginEvent([List props = const []]) : super(props);
Future<LoginState> applyAsync(
{LoginState currentState, LoginBloc bloc});
final LoginRepository _loginRepository = new LoginRepository();
}
class LoadLoginEvent extends LoginEvent {
final int index;
@override
String toString() => 'LoadLoginEvent';
LoadLoginEvent(this.index) : super([index]);
@override
Future<LoginState> applyAsync(
{LoginState currentState, LoginBloc bloc}) async {
try {
// await Future.delayed(new Duration(seconds: 2));
// this._loginRepository.test();
return new InLoginState(Random().nextInt(1000));
} catch (_, stackTrace) {
print('$_ $stackTrace');
return new ErrorLoginState(_?.toString());
}
}
}
Thanks
TN commented
This is because I am using a Singleton bloc for the screen. So it is not getting initialized once the screen is going out of the Widget tree.
Can you review the bloc template. it is using singleton. maybe out of date
thanks