Added credentials form.
This commit is contained in:
parent
cdc04a3401
commit
2a2dafcec8
80
lib/ui/credentials_form.dart
Normal file
80
lib/ui/credentials_form.dart
Normal 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;
|
||||
})
|
||||
])
|
||||
]),
|
||||
]));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user