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),
        }
    }
}

Libraries

single_result_bloc