Created with <3 with dartpad.dev.
Last active
July 18, 2022 12:24
-
-
Save mannuelf/d7c6ff62cbba5babdb309d5f9378d202 to your computer and use it in GitHub Desktop.
bloc-pattern-login-form
This file contains 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'; | |
void main() { | |
final bloc = Bloc(); | |
// bad pattern | |
// bloc.emailController.stream.listen((value) { | |
// print(value); | |
// }); | |
// bad pattern | |
// bloc.emailController.sink.add('MY NEW EMAIL'); | |
// good pattern | |
bloc.email.listen((value) => print(value)); | |
// call methods: good pattern | |
bloc.changeEmail('batter up'); | |
} | |
class Bloc { | |
final emailController = StreamController<String>(); | |
final passwordController = StreamController<String>(); | |
// setup methods | |
// Add data to stream | |
Function(String) get changeEmail => emailController.sink.add; | |
Function(String) get changePassword => passwordController.sink.add; | |
// Retrieve data from stream | |
Stream<String> get email => emailController.stream; | |
Stream<String> get password => passwordController.stream; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment