From 32fa6455f4f67dc87dfed5461d17a12eadc021c2 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Tue, 23 Apr 2019 08:46:50 +0200 Subject: [PATCH] Improved login page --- lib/ui/routes/login_route.dart | 32 +++++++++++++++++++++----------- lib/utils/ui_utils.dart | 12 +++++++++--- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/ui/routes/login_route.dart b/lib/ui/routes/login_route.dart index 7e4bce5..1c8880c 100644 --- a/lib/ui/routes/login_route.dart +++ b/lib/ui/routes/login_route.dart @@ -19,6 +19,7 @@ class _LoginRouteState extends State { String _currEmail; String _currPassword; AuthResult _authResult; + bool _loading = false; @override void initState() { @@ -41,6 +42,10 @@ class _LoginRouteState extends State { /// Call this whenever the user request to perform login Future _submitForm(BuildContext context) async { + setState(() { + _loading = true; + }); + final loginResult = await AccountHelper().signIn( AuthenticationDetails(email: _currEmail, password: _currPassword)); @@ -50,19 +55,21 @@ class _LoginRouteState extends State { else setState(() { _authResult = loginResult; + _loading = false; }); } // Build error card Widget _buildErrorCard() { - if (_authResult == null) - return null; + if (_authResult == null) return null; //Determine the right message - final message = (_authResult == AuthResult.INVALID_CREDENTIALS ? tr( - "Invalid credentials!") : (_authResult == AuthResult.TOO_MANY_ATTEMPTS - ? tr("Too many unsuccessfull login attempts! Please try again later...") - : tr("A network error occured!"))); + final message = (_authResult == AuthResult.INVALID_CREDENTIALS + ? tr("Invalid credentials!") + : (_authResult == AuthResult.TOO_MANY_ATTEMPTS + ? tr( + "Too many unsuccessfull login attempts! Please try again later...") + : tr("A network error occured!"))); return buildErrorCard(message); } @@ -100,11 +107,14 @@ class _LoginRouteState extends State { onChanged: _passwordChanged, ), - RaisedButton( - child: Text(tr("Sign in")), - onPressed: !validateEmail(_currEmail) || _currPassword.length < 3 - ? null - : () => _submitForm(context), + Container( + padding: EdgeInsets.all(8.0), + child: _loading ? CircularProgressIndicator() : RaisedButton( + child: Text(tr("Sign in")), + onPressed: !validateEmail(_currEmail) || _currPassword.length < 3 + ? null + : () => _submitForm(context), + ), ) ], ), diff --git a/lib/utils/ui_utils.dart b/lib/utils/ui_utils.dart index db8b13d..be5b919 100644 --- a/lib/utils/ui_utils.dart +++ b/lib/utils/ui_utils.dart @@ -2,12 +2,18 @@ import 'package:flutter/material.dart'; /// User interface utilities +/// Build centered progress bar +Widget buildCenteredProgressBar() { + return Center( + child: CircularProgressIndicator(), + ); +} + + /// Build and return a full loading page Widget buildLoadingPage() { return Scaffold( - body: Center( - child: CircularProgressIndicator(), - ), + body: buildCenteredProgressBar(), ); }