Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LoginForm extends StatelessWidget {
- final LoginBloc loginBloc;
- final usernameController = TextEditingController();
- final passwordController = TextEditingController();
- const LoginForm({Key key, @required this.loginBloc}): super(key: key);
- @override
- Widget build(BuildContext context) {
- return BlocBuilder<LoginState>(
- bloc: loginBloc,
- builder: (
- BuildContext context,
- LoginState loginState,
- ) {
- if (loginState.token.isNotEmpty) {
- // user is authenticated do something...
- }
- return Form(
- child: Column(
- children: [
- Text(
- loginState.error,
- ),
- TextFormField(
- controller: usernameController,
- ),
- TextFormField(
- controller: passwordController,
- obscureText: true,
- ),
- RaisedButton(
- onPressed: loginState.isLoginButtonEnabled
- ? _onLoginButtonPressed
- : null,
- child: Text('Login'),
- ),
- Container(
- child: loginState.isLoading
- ? CircularProgressIndicator()
- : null,
- ),
- ],
- ),
- );
- },
- );
- }
- _onLoginButtonPressed() {
- loginBloc.onLoginButtonPressed(
- username: usernameController.text,
- password: passwordController.text,
- );
- }
- }
Add Comment
Please, Sign In to add comment