Created
March 15, 2019 22:43
-
-
Save ruan65/263fe840e43c4d29c314bf192e41915b 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/claims/create_clame/bloc/export.dart'; | |
import 'package:tps_mobile_combined_maximo_app/data/model/claims/claim_co.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 CreateClaimBloc extends Bloc<CreateClaimEvent, CreateClaimState> { | |
final GlobalBloc globalBloc; | |
CreateClaimBloc(this.globalBloc); | |
@override | |
CreateClaimState get initialState => CreateOrUpdateClaimState(); | |
@override | |
Stream<CreateClaimState> mapEventToState( | |
CreateClaimState currentState, | |
CreateClaimEvent event, | |
) async* { | |
if (event is SaveClaimEvent) { | |
yield* _mapSaveClaimEventToState(event.claimCo); | |
} | |
} | |
Stream<CreateClaimState> _mapSaveClaimEventToState(ClaimCo claim) async* { | |
try { | |
await LocalStorage.saveClaim(claim); | |
yield ClaimSavedState(); | |
globalBloc.globalMessage(GlobalMessage.NEED_UPDATE_CLAIM_LIST); | |
} catch (_) { | |
yield ClaimNotSavedState(); | |
} | |
} | |
saveClaim(ClaimCo claim) { | |
dispatch(SaveClaimEvent(claim)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment