single_result_bloc 0.0.1 copy "single_result_bloc: ^0.0.1" to clipboard
single_result_bloc: ^0.0.1 copied to clipboard

outdated

Bloc extension, that adds support of one-time events

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),
        }
    }
}
2
likes
0
points
23
downloads

Publisher

verified publisherae-mc.ru

Weekly Downloads

Bloc extension, that adds support of one-time events

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_bloc

More

Packages that depend on single_result_bloc