1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 04:49:21 +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 _currPassword;
AuthResult _authResult;
bool _loading = false;
@override
void initState() {
@ -41,6 +42,10 @@ class _LoginRouteState extends State<LoginRoute> {
/// Call this whenever the user request to perform login
Future<void> _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<LoginRoute> {
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<LoginRoute> {
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),
),
)
],
),

View File

@ -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(),
);
}