BotZ_app/lib/ui/credentials_form.dart

81 lines
2.2 KiB
Dart
Raw Normal View History

2019-08-18 23:05:24 +02:00
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;
})
])
]),
]));
}
}