From acf2b0d8e9ee9ada61439083cb10140c40eee332 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 23 Apr 2019 17:36:22 +0200 Subject: [PATCH] Can submit login form from password field --- lib/ui/routes/login_route.dart | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/ui/routes/login_route.dart b/lib/ui/routes/login_route.dart index 1c8880c..6c88d9f 100644 --- a/lib/ui/routes/login_route.dart +++ b/lib/ui/routes/login_route.dart @@ -76,6 +76,9 @@ class _LoginRouteState extends State { /// Build login form Widget _buildLoginForm() { + // Whether the form can be submitted or not + final valid = validateEmail(_currEmail) && _currPassword.length >= 3; + return SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(8.0), @@ -105,16 +108,17 @@ class _LoginRouteState extends State { alignLabelWithHint: true, ), onChanged: _passwordChanged, + onSubmitted: valid ? (s) => _submitForm(context) : null, ), Container( padding: EdgeInsets.all(8.0), - child: _loading ? CircularProgressIndicator() : RaisedButton( - child: Text(tr("Sign in")), - onPressed: !validateEmail(_currEmail) || _currPassword.length < 3 - ? null - : () => _submitForm(context), - ), + child: _loading + ? CircularProgressIndicator() + : RaisedButton( + child: Text(tr("Sign in")), + onPressed: valid ? () => _submitForm(context) : null, + ), ) ], ),