Skip to content

Instantly share code, notes, and snippets.

@Fallenstedt

Fallenstedt/bloc.dart

Last active Jan 29, 2019
Embed
What would you like to do?
A simple bloc example
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