Guest User

Untitled

a guest
Oct 8th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. class LoginForm extends StatelessWidget {
  2. final LoginBloc loginBloc;
  3. final usernameController = TextEditingController();
  4. final passwordController = TextEditingController();
  5.  
  6. const LoginForm({Key key, @required this.loginBloc}): super(key: key);
  7.  
  8. @override
  9. Widget build(BuildContext context) {
  10. return BlocBuilder<LoginState>(
  11. bloc: loginBloc,
  12. builder: (
  13. BuildContext context,
  14. LoginState loginState,
  15. ) {
  16. if (loginState.token.isNotEmpty) {
  17. // user is authenticated do something...
  18. }
  19.  
  20. return Form(
  21. child: Column(
  22. children: [
  23. Text(
  24. loginState.error,
  25. ),
  26. TextFormField(
  27. controller: usernameController,
  28. ),
  29. TextFormField(
  30. controller: passwordController,
  31. obscureText: true,
  32. ),
  33. RaisedButton(
  34. onPressed: loginState.isLoginButtonEnabled
  35. ? _onLoginButtonPressed
  36. : null,
  37. child: Text('Login'),
  38. ),
  39. Container(
  40. child: loginState.isLoading
  41. ? CircularProgressIndicator()
  42. : null,
  43. ),
  44. ],
  45. ),
  46. );
  47. },
  48. );
  49. }
  50.  
  51. _onLoginButtonPressed() {
  52. loginBloc.onLoginButtonPressed(
  53. username: usernameController.text,
  54. password: passwordController.text,
  55. );
  56. }
  57. }
Add Comment
Please, Sign In to add comment