Added docs for the new image bloc

This commit is contained in:
Mariano Uvalle 2019-04-05 01:16:06 -06:00
parent 0725b2700e
commit 12ea8fec33

View file

@ -9,12 +9,24 @@ import '../services/auth_service.dart';
import '../resources/firebase_storage_provider.dart';
import '../resources/firestore_provider.dart';
/// A business logic component that manages the state for the new image screen.
class NewImageBloc {
/// An instance of the auth service.
final AuthService _auth = authService;
/// An instance of the firestore provider.
final FirestoreProvider _firestore = firestoreProvider;
/// An instance of the firebase storage provider.
final FirebaseStorageProvider _storage = storageProvider;
/// A subject of the current picture file.
final _picture = BehaviorSubject<File>();
/// A subject of the current user model.
final _user = BehaviorSubject<UserModel>();
/// A subject of the current task event name.
final _eventName = BehaviorSubject<String>();
NewImageBloc() {
@ -22,22 +34,34 @@ class NewImageBloc {
}
//Stream getters.
/// An observable of the picture file.
Observable<File> get picture => _picture.stream;
/// An observable of the user model.
Observable<UserModel> get userModelStream => _user.stream;
/// An observable of the task event name.
Observable<String> get eventName => _eventName.stream;
/// An observable of the ready to submit flag.
Observable<bool> get submitEnabled =>
Observable.combineLatest2(_picture, _eventName, (a, b) => true);
//Sink getters.
/// Changes the current picture file.
Function(File) get changePicture => _picture.sink.add;
/// Changes the current task event name.
Function(String) get changeEventName => _eventName.sink.add;
/// Fetches and updates the current user.
Future<void> setCurrentUser() async {
final user = await _auth.currentUser;
final userModel = await _firestore.getUser(username: user.email);
_user.add(userModel);
}
/// Saves the current picture to the database.
Future<void> submit() async {
final user = _user.value;
final StorageUploadTask uploadTask =