add dashboard to phone app
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../../core/providers/auth_provider.dart';
|
||||
|
||||
class EmployeeLoginScreen extends ConsumerStatefulWidget {
|
||||
@@ -36,15 +37,36 @@ class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
|
||||
_emailController.text.trim(),
|
||||
_passwordController.text,
|
||||
);
|
||||
} catch (e) {
|
||||
} on DioException catch (e) {
|
||||
setState(() {
|
||||
_error = 'Invalid email or password. Please try again.';
|
||||
_error = _messageForDioError(e);
|
||||
});
|
||||
} catch (_) {
|
||||
setState(() {
|
||||
_error = 'Sign in failed. Please try again.';
|
||||
});
|
||||
} finally {
|
||||
if (mounted) setState(() => _loading = false);
|
||||
}
|
||||
}
|
||||
|
||||
String _messageForDioError(DioException error) {
|
||||
final statusCode = error.response?.statusCode;
|
||||
if (statusCode == 401 || statusCode == 403) {
|
||||
return 'Invalid email or password. Please try again.';
|
||||
}
|
||||
|
||||
switch (error.type) {
|
||||
case DioExceptionType.connectionTimeout:
|
||||
case DioExceptionType.sendTimeout:
|
||||
case DioExceptionType.receiveTimeout:
|
||||
case DioExceptionType.connectionError:
|
||||
return 'Unable to reach the server. Check the API URL or your connection and try again.';
|
||||
default:
|
||||
return 'Sign in failed. Please try again.';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -107,6 +129,10 @@ class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
|
||||
controller: _emailController,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
textInputAction: TextInputAction.next,
|
||||
textCapitalization: TextCapitalization.none,
|
||||
autocorrect: false,
|
||||
enableSuggestions: false,
|
||||
autofillHints: const [AutofillHints.username, AutofillHints.email],
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Email',
|
||||
prefixIcon: Icon(Icons.email_outlined),
|
||||
@@ -120,6 +146,9 @@ class _EmployeeLoginScreenState extends ConsumerState<EmployeeLoginScreen> {
|
||||
controller: _passwordController,
|
||||
obscureText: _obscurePassword,
|
||||
textInputAction: TextInputAction.done,
|
||||
autocorrect: false,
|
||||
enableSuggestions: false,
|
||||
autofillHints: const [AutofillHints.password],
|
||||
onFieldSubmitted: (_) => _login(),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Password',
|
||||
|
||||
Reference in New Issue
Block a user