1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 06:53:23 +00:00

Improved login page

This commit is contained in:
Pierre HUBERT 2019-04-23 08:46:50 +02:00
parent 23f25e7704
commit 32fa6455f4
2 changed files with 30 additions and 14 deletions

View File

@ -19,6 +19,7 @@ class _LoginRouteState extends State<LoginRoute> {
String _currEmail; String _currEmail;
String _currPassword; String _currPassword;
AuthResult _authResult; AuthResult _authResult;
bool _loading = false;
@override @override
void initState() { void initState() {
@ -41,6 +42,10 @@ class _LoginRouteState extends State<LoginRoute> {
/// Call this whenever the user request to perform login /// Call this whenever the user request to perform login
Future<void> _submitForm(BuildContext context) async { Future<void> _submitForm(BuildContext context) async {
setState(() {
_loading = true;
});
final loginResult = await AccountHelper().signIn( final loginResult = await AccountHelper().signIn(
AuthenticationDetails(email: _currEmail, password: _currPassword)); AuthenticationDetails(email: _currEmail, password: _currPassword));
@ -50,18 +55,20 @@ class _LoginRouteState extends State<LoginRoute> {
else else
setState(() { setState(() {
_authResult = loginResult; _authResult = loginResult;
_loading = false;
}); });
} }
// Build error card // Build error card
Widget _buildErrorCard() { Widget _buildErrorCard() {
if (_authResult == null) if (_authResult == null) return null;
return null;
//Determine the right message //Determine the right message
final message = (_authResult == AuthResult.INVALID_CREDENTIALS ? tr( final message = (_authResult == AuthResult.INVALID_CREDENTIALS
"Invalid credentials!") : (_authResult == AuthResult.TOO_MANY_ATTEMPTS ? tr("Invalid credentials!")
? tr("Too many unsuccessfull login attempts! Please try again later...") : (_authResult == AuthResult.TOO_MANY_ATTEMPTS
? tr(
"Too many unsuccessfull login attempts! Please try again later...")
: tr("A network error occured!"))); : tr("A network error occured!")));
return buildErrorCard(message); return buildErrorCard(message);
@ -100,11 +107,14 @@ class _LoginRouteState extends State<LoginRoute> {
onChanged: _passwordChanged, onChanged: _passwordChanged,
), ),
RaisedButton( Container(
padding: EdgeInsets.all(8.0),
child: _loading ? CircularProgressIndicator() : RaisedButton(
child: Text(tr("Sign in")), child: Text(tr("Sign in")),
onPressed: !validateEmail(_currEmail) || _currPassword.length < 3 onPressed: !validateEmail(_currEmail) || _currPassword.length < 3
? null ? null
: () => _submitForm(context), : () => _submitForm(context),
),
) )
], ],
), ),

View File

@ -2,12 +2,18 @@ import 'package:flutter/material.dart';
/// User interface utilities /// User interface utilities
/// Build centered progress bar
Widget buildCenteredProgressBar() {
return Center(
child: CircularProgressIndicator(),
);
}
/// Build and return a full loading page /// Build and return a full loading page
Widget buildLoadingPage() { Widget buildLoadingPage() {
return Scaffold( return Scaffold(
body: Center( body: buildCenteredProgressBar(),
child: CircularProgressIndicator(),
),
); );
} }