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