Created
October 8, 2018 16:56
-
-
Save felangel/d39a3a70cb44274380b37cdfe06d772f to your computer and use it in GitHub Desktop.
[bloc_package] LoginForm
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
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, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment