Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. class Bloc with Validators {
  2. final _email = StreamController<String>();
  3. final _password = StreamController<String>();
  4.  
  5. Function(String) get sinkEmail => _email.sink.add;
  6.  
  7. Stream<String> get email => _email.stream.transform(validateEmail);
  8. // Stream<String> get email => _email.stream; //THIS IS WORKING
  9.  
  10. Function(String) get sinkPass => _password.sink.add;
  11.  
  12. Stream<String> get pass => _password.stream.transform(validatePassword);
  13. // Stream<String> get pass => _password.stream; //THIS TOO OFC
  14.  
  15. dispose() {
  16. _email.close();
  17. _password.close();
  18. }
  19. }
  20.  
  21. Widget _buildEmailField() {
  22. return StreamBuilder(
  23. stream: bloc.email,
  24. builder: (context, snapshot) {
  25. return TextField(
  26. keyboardType: TextInputType.emailAddress,
  27. onChanged: bloc.sinkEmail,
  28. decoration: InputDecoration(
  29. border: OutlineInputBorder(),
  30. labelText: 'Email Adress',
  31. hintText: 'you@example.com',
  32. errorText: snapshot.error,
  33. ),
  34. );
  35. });
  36. }
  37.  
  38. class Validators {
  39. final validateEmail =
  40. StreamTransformer<String, String>.fromHandlers(handleData: (email, sink) {
  41. if (email.contains('@')) {
  42. sink.add(email);
  43. } else {
  44. sink.addError('Enter a valid email');
  45. }
  46. });
  47. }
  48.  
  49. flutter: The following StateError was thrown building NotificationListener<KeepAliveNotification>:
  50. flutter: Bad state: Stream has already been listened to.
  51. flutter:
  52. flutter: When the exception was thrown, this was the stack:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement