Added credentials form.

master
blallo 2019-08-18 18:05:24 -03:00
parent cdc04a3401
commit 2a2dafcec8
Signed by: blallo
GPG Key ID: 0CBE577C9B72DC3F
1 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,80 @@
import 'package:flutter/material.dart';
class CredentialsForm extends StatefulWidget {
CredentialsForm({Key key}) : super(key: key);
@override
_CredentialsState createState() => _CredentialsState();
}
class _CredentialsState extends State<CredentialsForm> {
String username;
String password;
bool _hidden = true;
final _credFormKey = GlobalKey<FormState>();
InputDecoration _textFieldDecoration(String label, IconData icon) {
return InputDecoration(
labelText: label,
icon: Icon(icon),
hintText: 'Please, insert your zucchetti account $label',
);
}
String validateUsername(String username) {
if (username.isEmpty) {
return 'Username must not be empty';
}
return null;
}
String validatePassword(String password) {
if (password.isEmpty) {
return 'Password must not be empty';
}
return null;
}
@override
Widget build(BuildContext context) {
return Form(
key: _credFormKey,
child: Column(children: <Widget>[
TextFormField(
autofocus: true,
autocorrect: false,
decoration:
this._textFieldDecoration("username", Icons.alternate_email),
validator: this.validateUsername),
TextFormField(
autocorrect: false,
decoration: this._textFieldDecoration("password", Icons.lock),
validator: this.validatePassword,
obscureText: this._hidden),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
RaisedButton(
onPressed: () {
if (_credFormKey.currentState.validate()) {
Scaffold.of(context)
.showSnackBar(SnackBar(content: Text('Processing Data')));
}
},
child: Text('Validate'),
),
Row(children: <Widget>[
Text('Reveal password'),
Checkbox(
value: !this._hidden,
onChanged: (bool value) {
setState(() {
_hidden = !value;
});
return;
})
])
]),
]));
}
}