Example Authentication Bloc
import'dart:async'; import'package:bloc/bloc.dart'; import'package:bokeh/bokeh.dart'; part'authentication_bloc.g.dart'; /// Events@protocolabstractclass_AuthenticationEvent{appStarted(int timestamp); credentialUpdated({String login, String password ="loremIpsum"}); loggedIn(); loggedOut()} /// States@protocolabstractclass_AuthenticationState{idle(); loading({int progress, String message}); error(Exception e)} /// Bloc@BlocOf(state:_AuthenticationState, event:_AuthenticationEvent) classAuthenticationBlocextendsBloc<AuthenticationEvent, AuthenticationState>{@overrideAuthenticationStateget initialState =>AuthenticationState.idle(); @overrideStream<AuthenticationState> mapEventToState( AuthenticationEvent event) async*{yield* event.when( // appStarted: (_) async*{final current = state asLoading; yield current.copyWith(progress:20); awaitFuture.delayed(Duration(seconds:2)); yieldAuthenticationState.idle(); yieldAuthenticationState.loading(); awaitFuture.delayed(Duration(seconds:4)); yieldAuthenticationState.loading(progress:200); yieldAuthenticationState.idle()}, // credentialUpdated: (_) async*{awaitFuture.delayed(Duration())}, // loggedOut: () async*{yieldAuthenticationState.idle()}, loggedIn: () async*{// skip }, )} }