Advertisement
Guest User

Untitled

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