login_screen.dart 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import 'package:flutter/material.dart';
  2. import '../mixins/validator_mixin.dart';
  3. class LoginScreen extends StatefulWidget {
  4. @override
  5. State<StatefulWidget> createState() {
  6. return LoginScreenState();
  7. }
  8. }
  9. class LoginScreenState extends State<LoginScreen> with LoginValidators {
  10. final formKey = GlobalKey<FormState>();
  11. String _email = '';
  12. String _password = '';
  13. @override
  14. Widget build(BuildContext context) {
  15. return Container(
  16. margin: EdgeInsets.all(20.0),
  17. child: Form(
  18. key: formKey,
  19. child: Column(
  20. children: <Widget>[
  21. emailField(),
  22. passwordField(),
  23. Container(
  24. margin: EdgeInsets.only(bottom: 10),
  25. ),
  26. submitButton(),
  27. ],
  28. ),
  29. ));
  30. }
  31. Widget emailField() {
  32. return TextFormField(
  33. onSaved: (value) {
  34. _email = value;
  35. },
  36. validator: validateEmail,
  37. keyboardType: TextInputType.emailAddress,
  38. decoration: InputDecoration(
  39. labelText: 'Enter Email Address', hintText: 'name@site.com'),
  40. );
  41. }
  42. Widget passwordField() {
  43. return TextFormField(
  44. onSaved: (value) {
  45. _password = value;
  46. },
  47. validator: validatePassword,
  48. obscureText: true,
  49. decoration: InputDecoration(
  50. labelText: 'Enter Password', hintText: 'at least 4 characters'),
  51. );
  52. }
  53. Widget submitButton() {
  54. return RaisedButton(
  55. child: Text('submit'),
  56. color: Colors.blue,
  57. onPressed: () {
  58. if (formKey.currentState.validate()) {
  59. formKey.currentState.save();
  60. print('email is $_email and the pass is $_password');
  61. }
  62. },
  63. );
  64. }
  65. }