5 changed files with 315 additions and 271 deletions
@ -1,4 +1,5 @@ |
|||
import 'package:flutter/material.dart'; |
|||
import 'package:flutter/services.dart'; |
|||
import './tables.dart'; |
|||
import '../layouts/main_layout.dart'; |
|||
|
|||
@ -54,6 +55,15 @@ class _LoginScreenState extends State<LoginScreen> { |
|||
super.dispose(); |
|||
} |
|||
|
|||
// Méthode pour gérer la touche Entrée |
|||
void _handleKeyPress(KeyEvent event) { |
|||
if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.enter) { |
|||
if (!_isLoading) { |
|||
_login(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void _login() async { |
|||
if (!_formKey.currentState!.validate()) return; |
|||
|
|||
@ -99,279 +109,295 @@ class _LoginScreenState extends State<LoginScreen> { |
|||
|
|||
@override |
|||
Widget build(BuildContext context) { |
|||
return Scaffold( |
|||
backgroundColor: const Color(0xFFF5F5F5), // Light gray background |
|||
body: Center( |
|||
child: SingleChildScrollView( |
|||
padding: const EdgeInsets.all(24.0), |
|||
child: Card( |
|||
elevation: 2, |
|||
shape: RoundedRectangleBorder( |
|||
borderRadius: BorderRadius.circular(8), |
|||
), |
|||
child: Container( |
|||
width: 400, |
|||
padding: const EdgeInsets.all(40.0), |
|||
child: Form( |
|||
key: _formKey, |
|||
child: Column( |
|||
mainAxisSize: MainAxisSize.min, |
|||
children: [ |
|||
// Logo personnalisé |
|||
Container( |
|||
width: 80, |
|||
height: 80, |
|||
child: Image.asset( |
|||
'assets/logo_transparent.png', |
|||
fit: BoxFit.contain, |
|||
errorBuilder: (context, error, stackTrace) { |
|||
// Fallback en cas d'erreur de chargement |
|||
return Container( |
|||
width: 64, |
|||
height: 64, |
|||
decoration: const BoxDecoration( |
|||
color: Colors.green, |
|||
shape: BoxShape.circle, |
|||
), |
|||
child: const Icon( |
|||
Icons.restaurant_menu, |
|||
color: Colors.white, |
|||
size: 32, |
|||
), |
|||
); |
|||
}, |
|||
return KeyboardListener( |
|||
focusNode: FocusNode(), |
|||
onKeyEvent: _handleKeyPress, |
|||
child: Scaffold( |
|||
backgroundColor: const Color(0xFFF5F5F5), // Light gray background |
|||
body: Center( |
|||
child: SingleChildScrollView( |
|||
padding: const EdgeInsets.all(24.0), |
|||
child: Card( |
|||
elevation: 2, |
|||
shape: RoundedRectangleBorder( |
|||
borderRadius: BorderRadius.circular(8), |
|||
), |
|||
child: Container( |
|||
width: 400, |
|||
padding: const EdgeInsets.all(40.0), |
|||
child: Form( |
|||
key: _formKey, |
|||
child: Column( |
|||
mainAxisSize: MainAxisSize.min, |
|||
children: [ |
|||
// Logo personnalisé |
|||
Container( |
|||
width: 80, |
|||
height: 80, |
|||
child: Image.asset( |
|||
'assets/logo_transparent.png', |
|||
fit: BoxFit.contain, |
|||
errorBuilder: (context, error, stackTrace) { |
|||
// Fallback en cas d'erreur de chargement |
|||
return Container( |
|||
width: 64, |
|||
height: 64, |
|||
decoration: const BoxDecoration( |
|||
color: Colors.green, |
|||
shape: BoxShape.circle, |
|||
), |
|||
child: const Icon( |
|||
Icons.restaurant_menu, |
|||
color: Colors.white, |
|||
size: 32, |
|||
), |
|||
); |
|||
}, |
|||
), |
|||
), |
|||
), |
|||
const SizedBox(height: 24), |
|||
const SizedBox(height: 24), |
|||
|
|||
// Title |
|||
const Text( |
|||
'Restaurant App', |
|||
style: TextStyle( |
|||
fontSize: 24, |
|||
fontWeight: FontWeight.bold, |
|||
color: Colors.black87, |
|||
// Title |
|||
const Text( |
|||
'Restaurant App', |
|||
style: TextStyle( |
|||
fontSize: 24, |
|||
fontWeight: FontWeight.bold, |
|||
color: Colors.black87, |
|||
), |
|||
), |
|||
), |
|||
const SizedBox(height: 8), |
|||
const SizedBox(height: 8), |
|||
|
|||
// Subtitle |
|||
const Text( |
|||
'Connectez-vous pour accéder au système de commandes', |
|||
style: TextStyle(color: Colors.grey, fontSize: 14), |
|||
textAlign: TextAlign.center, |
|||
), |
|||
const SizedBox(height: 32), |
|||
// Subtitle |
|||
const Text( |
|||
'Connectez-vous pour accéder au système de commandes', |
|||
style: TextStyle(color: Colors.grey, fontSize: 14), |
|||
textAlign: TextAlign.center, |
|||
), |
|||
const SizedBox(height: 32), |
|||
|
|||
// Error message |
|||
if (_errorMessage != null) |
|||
Container( |
|||
width: double.infinity, |
|||
padding: const EdgeInsets.all(12), |
|||
margin: const EdgeInsets.only(bottom: 16), |
|||
decoration: BoxDecoration( |
|||
color: Colors.red.shade50, |
|||
border: Border.all(color: Colors.red.shade200), |
|||
borderRadius: BorderRadius.circular(4), |
|||
// Error message |
|||
if (_errorMessage != null) |
|||
Container( |
|||
width: double.infinity, |
|||
padding: const EdgeInsets.all(12), |
|||
margin: const EdgeInsets.only(bottom: 16), |
|||
decoration: BoxDecoration( |
|||
color: Colors.red.shade50, |
|||
border: Border.all(color: Colors.red.shade200), |
|||
borderRadius: BorderRadius.circular(4), |
|||
), |
|||
child: Text( |
|||
_errorMessage!, |
|||
style: TextStyle( |
|||
color: Colors.red.shade600, |
|||
fontSize: 14, |
|||
), |
|||
textAlign: TextAlign.center, |
|||
), |
|||
), |
|||
|
|||
// Email label |
|||
const Align( |
|||
alignment: Alignment.centerLeft, |
|||
child: Text( |
|||
_errorMessage!, |
|||
'Email', |
|||
style: TextStyle( |
|||
color: Colors.red.shade600, |
|||
fontSize: 14, |
|||
color: Colors.black87, |
|||
fontWeight: FontWeight.w500, |
|||
), |
|||
textAlign: TextAlign.center, |
|||
), |
|||
), |
|||
const SizedBox(height: 8), |
|||
|
|||
// Email label |
|||
const Align( |
|||
alignment: Alignment.centerLeft, |
|||
child: Text( |
|||
'Email', |
|||
style: TextStyle( |
|||
fontSize: 14, |
|||
color: Colors.black87, |
|||
fontWeight: FontWeight.w500, |
|||
// Email field |
|||
TextFormField( |
|||
controller: emailController, |
|||
decoration: InputDecoration( |
|||
prefixIcon: const Icon( |
|||
Icons.email_outlined, |
|||
color: Colors.grey, |
|||
size: 20, |
|||
), |
|||
hintText: '[email protected]', |
|||
hintStyle: const TextStyle(color: Colors.grey), |
|||
border: OutlineInputBorder( |
|||
borderRadius: BorderRadius.circular(4), |
|||
borderSide: BorderSide(color: Colors.grey.shade300), |
|||
), |
|||
enabledBorder: OutlineInputBorder( |
|||
borderRadius: BorderRadius.circular(4), |
|||
borderSide: BorderSide(color: Colors.grey.shade300), |
|||
), |
|||
focusedBorder: OutlineInputBorder( |
|||
borderRadius: BorderRadius.circular(4), |
|||
borderSide: const BorderSide(color: Colors.green), |
|||
), |
|||
contentPadding: const EdgeInsets.symmetric( |
|||
horizontal: 12, |
|||
vertical: 16, |
|||
), |
|||
), |
|||
keyboardType: TextInputType.emailAddress, |
|||
textInputAction: TextInputAction.next, |
|||
validator: (value) { |
|||
if (value == null || value.isEmpty) { |
|||
return 'Veuillez entrer votre email'; |
|||
} |
|||
return null; |
|||
}, |
|||
), |
|||
), |
|||
const SizedBox(height: 8), |
|||
const SizedBox(height: 16), |
|||
|
|||
// Email field |
|||
TextFormField( |
|||
controller: emailController, |
|||
decoration: InputDecoration( |
|||
prefixIcon: const Icon( |
|||
Icons.email_outlined, |
|||
color: Colors.grey, |
|||
size: 20, |
|||
), |
|||
hintText: '[email protected]', |
|||
hintStyle: const TextStyle(color: Colors.grey), |
|||
border: OutlineInputBorder( |
|||
borderRadius: BorderRadius.circular(4), |
|||
borderSide: BorderSide(color: Colors.grey.shade300), |
|||
), |
|||
enabledBorder: OutlineInputBorder( |
|||
borderRadius: BorderRadius.circular(4), |
|||
borderSide: BorderSide(color: Colors.grey.shade300), |
|||
), |
|||
focusedBorder: OutlineInputBorder( |
|||
borderRadius: BorderRadius.circular(4), |
|||
borderSide: const BorderSide(color: Colors.green), |
|||
), |
|||
contentPadding: const EdgeInsets.symmetric( |
|||
horizontal: 12, |
|||
vertical: 16, |
|||
// Password label |
|||
const Align( |
|||
alignment: Alignment.centerLeft, |
|||
child: Text( |
|||
'Mot de passe', |
|||
style: TextStyle( |
|||
fontSize: 14, |
|||
color: Colors.black87, |
|||
fontWeight: FontWeight.w500, |
|||
), |
|||
), |
|||
), |
|||
keyboardType: TextInputType.emailAddress, |
|||
validator: (value) { |
|||
if (value == null || value.isEmpty) { |
|||
return 'Veuillez entrer votre email'; |
|||
} |
|||
return null; |
|||
}, |
|||
), |
|||
const SizedBox(height: 16), |
|||
const SizedBox(height: 8), |
|||
|
|||
// Password label |
|||
const Align( |
|||
alignment: Alignment.centerLeft, |
|||
child: Text( |
|||
'Mot de passe', |
|||
style: TextStyle( |
|||
fontSize: 14, |
|||
color: Colors.black87, |
|||
fontWeight: FontWeight.w500, |
|||
// Password field |
|||
TextFormField( |
|||
controller: passwordController, |
|||
decoration: InputDecoration( |
|||
prefixIcon: const Icon( |
|||
Icons.lock_outline, |
|||
color: Colors.grey, |
|||
size: 20, |
|||
), |
|||
hintText: '••••••••', |
|||
hintStyle: const TextStyle(color: Colors.grey), |
|||
border: OutlineInputBorder( |
|||
borderRadius: BorderRadius.circular(4), |
|||
borderSide: BorderSide(color: Colors.grey.shade300), |
|||
), |
|||
enabledBorder: OutlineInputBorder( |
|||
borderRadius: BorderRadius.circular(4), |
|||
borderSide: BorderSide(color: Colors.grey.shade300), |
|||
), |
|||
focusedBorder: OutlineInputBorder( |
|||
borderRadius: BorderRadius.circular(4), |
|||
borderSide: const BorderSide(color: Colors.green), |
|||
), |
|||
contentPadding: const EdgeInsets.symmetric( |
|||
horizontal: 12, |
|||
vertical: 16, |
|||
), |
|||
), |
|||
obscureText: true, |
|||
textInputAction: TextInputAction.done, |
|||
onFieldSubmitted: (_) => _login(), // Validation quand on appuie sur Entrée |
|||
validator: (value) { |
|||
if (value == null || value.isEmpty) { |
|||
return 'Veuillez entrer votre mot de passe'; |
|||
} |
|||
return null; |
|||
}, |
|||
), |
|||
), |
|||
const SizedBox(height: 8), |
|||
const SizedBox(height: 24), |
|||
|
|||
// Password field |
|||
TextFormField( |
|||
controller: passwordController, |
|||
decoration: InputDecoration( |
|||
prefixIcon: const Icon( |
|||
Icons.lock_outline, |
|||
color: Colors.grey, |
|||
size: 20, |
|||
), |
|||
hintText: '••••••••', |
|||
hintStyle: const TextStyle(color: Colors.grey), |
|||
border: OutlineInputBorder( |
|||
borderRadius: BorderRadius.circular(4), |
|||
borderSide: BorderSide(color: Colors.grey.shade300), |
|||
), |
|||
enabledBorder: OutlineInputBorder( |
|||
borderRadius: BorderRadius.circular(4), |
|||
borderSide: BorderSide(color: Colors.grey.shade300), |
|||
), |
|||
focusedBorder: OutlineInputBorder( |
|||
borderRadius: BorderRadius.circular(4), |
|||
borderSide: const BorderSide(color: Colors.green), |
|||
), |
|||
contentPadding: const EdgeInsets.symmetric( |
|||
horizontal: 12, |
|||
vertical: 16, |
|||
// Login button |
|||
SizedBox( |
|||
width: double.infinity, |
|||
height: 48, |
|||
child: ElevatedButton( |
|||
onPressed: _isLoading ? null : _login, |
|||
style: ElevatedButton.styleFrom( |
|||
backgroundColor: Colors.green, |
|||
foregroundColor: Colors.white, |
|||
shape: RoundedRectangleBorder( |
|||
borderRadius: BorderRadius.circular(4), |
|||
), |
|||
elevation: 0, |
|||
), |
|||
child: |
|||
_isLoading |
|||
? const SizedBox( |
|||
height: 20, |
|||
width: 20, |
|||
child: CircularProgressIndicator( |
|||
color: Colors.white, |
|||
strokeWidth: 2, |
|||
), |
|||
) |
|||
: const Text( |
|||
'Se connecter', |
|||
style: TextStyle( |
|||
fontSize: 16, |
|||
fontWeight: FontWeight.w500, |
|||
), |
|||
), |
|||
), |
|||
), |
|||
obscureText: true, |
|||
validator: (value) { |
|||
if (value == null || value.isEmpty) { |
|||
return 'Veuillez entrer votre mot de passe'; |
|||
} |
|||
return null; |
|||
}, |
|||
), |
|||
const SizedBox(height: 24), |
|||
const SizedBox(height: 24), |
|||
|
|||
// Login button |
|||
SizedBox( |
|||
width: double.infinity, |
|||
height: 48, |
|||
child: ElevatedButton( |
|||
onPressed: _isLoading ? null : _login, |
|||
style: ElevatedButton.styleFrom( |
|||
backgroundColor: Colors.green, |
|||
foregroundColor: Colors.white, |
|||
shape: RoundedRectangleBorder( |
|||
borderRadius: BorderRadius.circular(4), |
|||
), |
|||
elevation: 0, |
|||
// Demo accounts section |
|||
Container( |
|||
width: double.infinity, |
|||
padding: const EdgeInsets.all(16), |
|||
decoration: BoxDecoration( |
|||
color: Colors.grey.shade100, |
|||
borderRadius: BorderRadius.circular(4), |
|||
), |
|||
child: |
|||
_isLoading |
|||
? const SizedBox( |
|||
height: 20, |
|||
width: 20, |
|||
child: CircularProgressIndicator( |
|||
color: Colors.white, |
|||
strokeWidth: 2, |
|||
child: Column( |
|||
crossAxisAlignment: CrossAxisAlignment.start, |
|||
children: [ |
|||
const Text( |
|||
'Comptes de démonstration :', |
|||
style: TextStyle( |
|||
fontSize: 14, |
|||
fontWeight: FontWeight.w500, |
|||
color: Colors.black87, |
|||
), |
|||
), |
|||
const SizedBox(height: 8), |
|||
RichText( |
|||
text: const TextSpan( |
|||
style: TextStyle( |
|||
fontSize: 13, |
|||
color: Colors.grey, |
|||
height: 1.4, |
|||
), |
|||
children: [ |
|||
TextSpan( |
|||
text: 'Serveur : ', |
|||
style: TextStyle(fontWeight: FontWeight.w500), |
|||
), |
|||
) |
|||
: const Text( |
|||
'Se connecter', |
|||
style: TextStyle( |
|||
fontSize: 16, |
|||
fontWeight: FontWeight.w500, |
|||
TextSpan( |
|||
text: '[email protected] / serveur123\n', |
|||
), |
|||
), |
|||
), |
|||
), |
|||
const SizedBox(height: 24), |
|||
|
|||
// Demo accounts section |
|||
Container( |
|||
width: double.infinity, |
|||
padding: const EdgeInsets.all(16), |
|||
decoration: BoxDecoration( |
|||
color: Colors.grey.shade100, |
|||
borderRadius: BorderRadius.circular(4), |
|||
), |
|||
child: Column( |
|||
crossAxisAlignment: CrossAxisAlignment.start, |
|||
children: [ |
|||
const Text( |
|||
'Comptes de démonstration :', |
|||
style: TextStyle( |
|||
fontSize: 14, |
|||
fontWeight: FontWeight.w500, |
|||
color: Colors.black87, |
|||
TextSpan( |
|||
text: 'Admin : ', |
|||
style: TextStyle(fontWeight: FontWeight.w500), |
|||
), |
|||
TextSpan( |
|||
text: '[email protected] / admin123', |
|||
), |
|||
], |
|||
), |
|||
), |
|||
), |
|||
const SizedBox(height: 8), |
|||
RichText( |
|||
text: const TextSpan( |
|||
const SizedBox(height: 8), |
|||
const Text( |
|||
'Astuce : Appuyez sur Entrée pour vous connecter', |
|||
style: TextStyle( |
|||
fontSize: 13, |
|||
fontSize: 12, |
|||
color: Colors.grey, |
|||
height: 1.4, |
|||
fontStyle: FontStyle.italic, |
|||
), |
|||
children: [ |
|||
TextSpan( |
|||
text: 'Serveur : ', |
|||
style: TextStyle(fontWeight: FontWeight.w500), |
|||
), |
|||
TextSpan( |
|||
text: '[email protected] / serveur123\n', |
|||
), |
|||
TextSpan( |
|||
text: 'Admin : ', |
|||
style: TextStyle(fontWeight: FontWeight.w500), |
|||
), |
|||
TextSpan( |
|||
text: '[email protected] / admin123', |
|||
), |
|||
], |
|||
), |
|||
), |
|||
], |
|||
], |
|||
), |
|||
), |
|||
), |
|||
], |
|||
], |
|||
), |
|||
), |
|||
), |
|||
), |
|||
@ -432,4 +458,4 @@ class HomeScreen extends StatelessWidget { |
|||
), |
|||
); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue