Created
September 29, 2020 03:18
-
-
Save andresgcarmona/0fe7f6c8e11ad69e2153ea3346553ecf to your computer and use it in GitHub Desktop.
Login form for Flutter
This file contains hidden or 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 'package:flutter/material.dart'; | |
class LoginForm extends StatefulWidget { | |
@override | |
_LoginFormState createState() => _LoginFormState(); | |
} | |
class _LoginFormState extends State<LoginForm> { | |
final _formKey = GlobalKey<FormState>(); | |
final _emailController = TextEditingController(); | |
@override | |
void initState() { | |
super.initState(); | |
_emailController.addListener(() { | |
Scaffold.of(context) | |
.showSnackBar(SnackBar(content: Text("Email value ${_emailController.text}"),)); | |
}); | |
} | |
@override | |
void dispose() { | |
_emailController.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Form( | |
key: _formKey, | |
child: Column( | |
children: <Widget>[ | |
TextFormField( | |
decoration: InputDecoration( | |
hintText: '[email protected]', labelText: 'Email'), | |
validator: (value) { | |
if (value.isEmpty) { | |
return 'Please enter some text'; | |
} | |
return null; | |
}, | |
controller: _emailController, | |
), | |
TextFormField( | |
decoration: InputDecoration( | |
hintText: 'Password', labelText: 'Password'), | |
obscureText: true, | |
validator: (value) { | |
if (value.isEmpty) { | |
return 'Please enter some text'; | |
} | |
return null; | |
}, | |
onChanged: (value) { | |
print("Password value $value"); | |
}, | |
), | |
RaisedButton( | |
onPressed: () { | |
if (_formKey.currentState.validate()) { | |
Scaffold.of(context).showSnackBar( | |
SnackBar(content: Text(_emailController.text))); | |
} | |
}, | |
child: Text('Submit'), | |
) | |
], | |
)), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment