From 2a2dafcec8b8b168a16c4e98917805afb2ce7838 Mon Sep 17 00:00:00 2001 From: blallo Date: Sun, 18 Aug 2019 18:05:24 -0300 Subject: [PATCH] Added credentials form. --- lib/ui/credentials_form.dart | 80 ++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 lib/ui/credentials_form.dart diff --git a/lib/ui/credentials_form.dart b/lib/ui/credentials_form.dart new file mode 100644 index 0000000..4e4c2dd --- /dev/null +++ b/lib/ui/credentials_form.dart @@ -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 { + String username; + String password; + bool _hidden = true; + final _credFormKey = GlobalKey(); + 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: [ + 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: [ + RaisedButton( + onPressed: () { + if (_credFormKey.currentState.validate()) { + Scaffold.of(context) + .showSnackBar(SnackBar(content: Text('Processing Data'))); + } + }, + child: Text('Validate'), + ), + Row(children: [ + Text('Reveal password'), + Checkbox( + value: !this._hidden, + onChanged: (bool value) { + setState(() { + _hidden = !value; + }); + return; + }) + ]) + ]), + ])); + } +}