Last updated:
0 purchases
single result bloc
SingleResultBloc #
This package adds additional SingleResult stream to standard State stream of
Bloc. This stream can be listened via SingleResultBlocBuilder's
onSingleResult parameter. This allows to send one-time events like showing
toasts or moving to another page after successful login for example.
Usage #
// auth_bloc.dart
class AuthBloc
extends SingleResultBloc<AuthEvent, AuthState, AuthSingleResult> {
AuthBloc() : super(AuthState.unauthorized()) {
on<AuthEventAuthorize>((event, emit) {
// somehow login
addSingleResult(const AuthSingleResult.loginSuccess());
});
}
}
// auth_page.dart
class AuthPage extends StatelessWidget {
Widget build(BuildContext context) {
return SingleResultBlocBuilder<AuthBloc, AuthState, AuthSingleResult> {
onSingleResult: (context, singleResult) {
if (singleResult is AuthSingleResultLoginSuccess) {
Navigator.of(context).pushReplacementNamed('login/success');
}
}
builder: (context, state) => LoginWidget(state),
}
}
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.