Created
October 6, 2019 18:24
-
-
Save adityadroid/7c266edd24ef6d3a0bd5fc65ae6da08a 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 'dart:async'; | |
| import 'package:bloc/bloc.dart'; | |
| import 'package:messio/config/Paths.dart'; | |
| import 'package:messio/repositories/StorageRepository.dart'; | |
| import 'package:messio/repositories/UserDataRepository.dart'; | |
| import 'package:messio/utils/SharedObjects.dart'; | |
| import 'Bloc.dart'; | |
| class ConfigBloc extends Bloc<ConfigEvent, ConfigState> { | |
| UserDataRepository userDataRepository; | |
| StorageRepository storageRepository; | |
| ConfigBloc({this.userDataRepository, this.storageRepository}) | |
| : assert(userDataRepository != null), | |
| assert(storageRepository != null); | |
| @override | |
| ConfigState get initialState => UnConfigState(); | |
| @override | |
| Stream<ConfigState> mapEventToState( | |
| ConfigEvent event, | |
| ) async* { | |
| if (event is ConfigValueChanged) { | |
| SharedObjects.prefs.setBool(event.key, event.value); | |
| yield ConfigChangeState(event.key, event.value); | |
| } | |
| if (event is UpdateProfilePicture) { | |
| yield* mapUpdateProfilePictureToState(event); | |
| } | |
| } | |
| Stream<ConfigState> mapUpdateProfilePictureToState( | |
| UpdateProfilePicture event) async* { | |
| yield UpdatingProfilePictureState(); | |
| final profilePictureUrl = await storageRepository.uploadFile(event.file, Paths.profilePicturePath); | |
| await userDataRepository.updateProfilePicture(profilePictureUrl); | |
| yield ProfilePictureChangedState(profilePictureUrl); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment