Last active
January 29, 2019 04:10
-
-
Save Fallenstedt/d87ec4a7a6224a17cdddef730843dbe2 to your computer and use it in GitHub Desktop.
A simple bloc example
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 'validators.dart'; | |
| import 'package:rxdart/rxdart.dart'; | |
| class Bloc with Validators { | |
| final _email = BehaviorSubject<String>(); | |
| final _password = BehaviorSubject<String>(); | |
| Stream<String> get email => _email.stream.transform(validateEmail); | |
| Stream<String> get password => _password.stream.transform(validatePassword); | |
| Stream<bool> get submitValid => | |
| Observable.combineLatest2(email, password, (e, p) => true); | |
| Function(String) get changeEmail => _email.sink.add; | |
| Function(String) get changePassword => _password.sink.add; | |
| submit() { | |
| final validEmail = _email.value; | |
| final validPassword = _password.value; | |
| print('$validEmail, $validPassword'); | |
| } | |
| dispose() { | |
| _email.close(); | |
| _password.close(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment