Created
March 15, 2019 22:40
-
-
Save ruan65/edd7a450849d8609ceb5caebf1ddfd83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:bloc/bloc.dart'; | |
import 'package:tps_mobile_combined_maximo_app/data/model/user_state/member_user_state.dart'; | |
import 'package:tps_mobile_combined_maximo_app/data/repositories/local_storage.dart'; | |
import 'package:tps_mobile_combined_maximo_app/global/bloc/export.dart'; | |
class GlobalBloc extends Bloc<GlobalEvent, GlobalState> { | |
@override | |
GlobalState get initialState => GlobalStateUnauthenticated(); | |
@override | |
Stream<GlobalState> mapEventToState( | |
GlobalState currentState, | |
GlobalEvent event, | |
) async* { | |
if(event is GlobalMessageEvent) { | |
yield GlobalMessageState(event.message); | |
} | |
if(event is GlobalAvoidDistinctEvent) { | |
yield GlobalStateAvoidDistinct(); | |
} | |
if(event is AppStartedGlobalEvent) { | |
yield GlobalStateCheckingAuthentication(); | |
} | |
if(event is AuthenticatedGlobalEvent) { | |
yield GlobalStateAuthenticated(); | |
} | |
if(event is UnauthenticatedGlobalEvent) { | |
yield GlobalStateUnauthenticated(); | |
LocalStorage.eraseUserState(); | |
} | |
} | |
void authenticated() => this.dispatch(AuthenticatedGlobalEvent()); | |
void unAuthenticated() => this.dispatch(UnauthenticatedGlobalEvent()); | |
Future<MemberUserState> currentUser() async { | |
return await LocalStorage.readUserState(); | |
} | |
void globalMessage(GlobalMessage message) { | |
dispatch(GlobalMessageEvent(message)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment