Compare commits

..

No commits in common. "e8c6665a060e04d6183b9ae371a617990ac930e3" and "80d69a5463c86f42fe3808a6eb2412a96c22ff1d" have entirely different histories.

3 changed files with 227 additions and 308 deletions

View File

@ -1,6 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
@ -21,7 +20,7 @@ class _LoginPageState extends State<LoginScreen> with WidgetsBindingObserver {
final _formKey = GlobalKey<FormState>(); final _formKey = GlobalKey<FormState>();
final _emailController = TextEditingController(); final _emailController = TextEditingController();
final _passwordController = TextEditingController(); final _passwordController = TextEditingController();
bool _isLoading = false; bool _isLoading = false;
String? _errorMessage; String? _errorMessage;
@ -64,11 +63,6 @@ class _LoginPageState extends State<LoginScreen> with WidgetsBindingObserver {
return null; return null;
} }
void _handlePasswordSubmitted(String _) {
if (_isLoading) return;
_handleLogin();
}
/// Gère la connexion de l'utilisateur /// Gère la connexion de l'utilisateur
Future<void> _handleLogin() async { Future<void> _handleLogin() async {
// Réinitialiser le message d'erreur // Réinitialiser le message d'erreur
@ -96,7 +90,7 @@ class _LoginPageState extends State<LoginScreen> with WidgetsBindingObserver {
// Vérifier si l'utilisateur doit changer son mot de passe // Vérifier si l'utilisateur doit changer son mot de passe
if (user.changementMdpObligatoire) { if (user.changementMdpObligatoire) {
if (!mounted) return; if (!mounted) return;
// Afficher la modale de changement de mot de passe (non-dismissible) // Afficher la modale de changement de mot de passe (non-dismissible)
final result = await showDialog<bool>( final result = await showDialog<bool>(
context: context, context: context,
@ -112,9 +106,6 @@ class _LoginPageState extends State<LoginScreen> with WidgetsBindingObserver {
if (!mounted) return; if (!mounted) return;
// Laisse au navigateur/OS la possibilité de mémoriser les identifiants.
TextInput.finishAutofillContext(shouldSave: true);
// Rediriger selon le rôle de l'utilisateur // Rediriger selon le rôle de l'utilisateur
_redirectUserByRole(user.role); _redirectUserByRole(user.role);
} catch (e) { } catch (e) {
@ -161,49 +152,47 @@ class _LoginPageState extends State<LoginScreen> with WidgetsBindingObserver {
final w = constraints.maxWidth; final w = constraints.maxWidth;
final h = constraints.maxHeight; final h = constraints.maxHeight;
return FutureBuilder( return FutureBuilder(
future: _getImageDimensions(), future: _getImageDimensions(),
builder: (context, snapshot) { builder: (context, snapshot) {
if (!snapshot.hasData) { if (!snapshot.hasData) {
return const Center(child: CircularProgressIndicator()); return const Center(child: CircularProgressIndicator());
} }
final imageDimensions = snapshot.data!; final imageDimensions = snapshot.data!;
final imageHeight = h; final imageHeight = h;
final imageWidth = imageHeight * final imageWidth = imageHeight * (imageDimensions.width / imageDimensions.height);
(imageDimensions.width / imageDimensions.height); final remainingWidth = w - imageWidth;
final remainingWidth = w - imageWidth; final leftMargin = remainingWidth / 4;
final leftMargin = remainingWidth / 4;
return Stack( return Stack(
children: [ children: [
// Fond en papier // Fond en papier
Positioned.fill( Positioned.fill(
child: Image.asset( child: Image.asset(
'assets/images/paper2.png', 'assets/images/paper2.png',
fit: BoxFit.cover, fit: BoxFit.cover,
repeat: ImageRepeat.repeat, repeat: ImageRepeat.repeat,
),
), ),
), // Image principale
// Image principale Positioned(
Positioned( left: leftMargin,
left: leftMargin, top: 0,
top: 0, height: imageHeight,
height: imageHeight, width: imageWidth,
width: imageWidth, child: Image.asset(
child: Image.asset( 'assets/images/river_logo_desktop.png',
'assets/images/river_logo_desktop.png', fit: BoxFit.contain,
fit: BoxFit.contain, ),
), ),
), // Formulaire dans le cadran en bas à droite
// Formulaire dans le cadran en bas à droite Positioned(
Positioned( right: 0,
right: 0, bottom: 0,
bottom: 0, width: w * 0.6, // 60% de la largeur de l'écran
width: w * 0.6, // 60% de la largeur de l'écran height: h * 0.5, // 50% de la hauteur de l'écran
height: h * 0.5, // 50% de la hauteur de l'écran child: Padding(
child: Padding( padding: EdgeInsets.all(w * 0.02), // 2% de padding
padding: EdgeInsets.all(w * 0.02), // 2% de padding
child: AutofillGroup(
child: Form( child: Form(
key: _formKey, key: _formKey,
child: Column( child: Column(
@ -218,12 +207,6 @@ class _LoginPageState extends State<LoginScreen> with WidgetsBindingObserver {
controller: _emailController, controller: _emailController,
labelText: 'Email', labelText: 'Email',
hintText: 'Votre adresse email', hintText: 'Votre adresse email',
keyboardType: TextInputType.emailAddress,
autofillHints: const [
AutofillHints.username,
AutofillHints.email,
],
textInputAction: TextInputAction.next,
validator: _validateEmail, validator: _validateEmail,
style: CustomAppTextFieldStyle.lavande, style: CustomAppTextFieldStyle.lavande,
fieldHeight: 53, fieldHeight: 53,
@ -237,12 +220,6 @@ class _LoginPageState extends State<LoginScreen> with WidgetsBindingObserver {
labelText: 'Mot de passe', labelText: 'Mot de passe',
hintText: 'Votre mot de passe', hintText: 'Votre mot de passe',
obscureText: true, obscureText: true,
autofillHints: const [
AutofillHints.password
],
textInputAction: TextInputAction.done,
onFieldSubmitted:
_handlePasswordSubmitted,
validator: _validatePassword, validator: _validatePassword,
style: CustomAppTextFieldStyle.jaune, style: CustomAppTextFieldStyle.jaune,
fieldHeight: 53, fieldHeight: 53,
@ -252,7 +229,7 @@ class _LoginPageState extends State<LoginScreen> with WidgetsBindingObserver {
], ],
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
// Message d'erreur // Message d'erreur
if (_errorMessage != null) if (_errorMessage != null)
Container( Container(
@ -265,8 +242,7 @@ class _LoginPageState extends State<LoginScreen> with WidgetsBindingObserver {
), ),
child: Row( child: Row(
children: [ children: [
Icon(Icons.error_outline, Icon(Icons.error_outline, color: Colors.red[700], size: 20),
color: Colors.red[700], size: 20),
const SizedBox(width: 10), const SizedBox(width: 10),
Expanded( Expanded(
child: Text( child: Text(
@ -280,7 +256,7 @@ class _LoginPageState extends State<LoginScreen> with WidgetsBindingObserver {
], ],
), ),
), ),
// Bouton centré // Bouton centré
Center( Center(
child: _isLoading child: _isLoading
@ -333,68 +309,67 @@ class _LoginPageState extends State<LoginScreen> with WidgetsBindingObserver {
), ),
), ),
), ),
), // Pied de page (Wrap pour éviter overflow sur petite largeur)
// Pied de page (Wrap pour éviter overflow sur petite largeur) Positioned(
Positioned( left: 0,
left: 0, right: 0,
right: 0, bottom: 0,
bottom: 0, child: Container(
child: Container( padding: const EdgeInsets.symmetric(vertical: 8.0),
padding: const EdgeInsets.symmetric(vertical: 8.0), decoration: const BoxDecoration(
decoration: const BoxDecoration( color: Colors.transparent,
color: Colors.transparent, ),
), child: Wrap(
child: Wrap( alignment: WrapAlignment.center,
alignment: WrapAlignment.center, runSpacing: 8,
runSpacing: 8, children: [
children: [ _FooterLink(
_FooterLink( text: 'Contact support',
text: 'Contact support', onTap: () async {
onTap: () async { final Uri emailLaunchUri = Uri(
final Uri emailLaunchUri = Uri( scheme: 'mailto',
scheme: 'mailto', path: 'support@supernounou.local',
path: 'support@supernounou.local',
);
if (await canLaunchUrl(emailLaunchUri)) {
await launchUrl(emailLaunchUri);
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Impossible d\'ouvrir le client mail',
style: GoogleFonts.merienda(),
),
),
); );
} if (await canLaunchUrl(emailLaunchUri)) {
}, await launchUrl(emailLaunchUri);
), } else {
_FooterLink( ScaffoldMessenger.of(context).showSnackBar(
text: 'Signaler un bug', SnackBar(
onTap: () { content: Text(
_showBugReportDialog(context); 'Impossible d\'ouvrir le client mail',
}, style: GoogleFonts.merienda(),
), ),
_FooterLink( ),
text: 'Mentions légales', );
onTap: () { }
context.go('/legal'); },
}, ),
), _FooterLink(
_FooterLink( text: 'Signaler un bug',
text: 'Politique de confidentialité', onTap: () {
onTap: () { _showBugReportDialog(context);
context.go('/privacy'); },
}, ),
), _FooterLink(
], text: 'Mentions légales',
onTap: () {
context.go('/legal');
},
),
_FooterLink(
text: 'Politique de confidentialité',
onTap: () {
context.go('/privacy');
},
),
],
),
), ),
), ),
), ],
], );
); },
}, );
);
}, },
), ),
); );
@ -403,7 +378,6 @@ class _LoginPageState extends State<LoginScreen> with WidgetsBindingObserver {
/// Dimensions de river_logo_mobile.png (à mettre à jour si l'asset change). /// Dimensions de river_logo_mobile.png (à mettre à jour si l'asset change).
static const int _riverLogoMobileWidth = 600; static const int _riverLogoMobileWidth = 600;
static const int _riverLogoMobileHeight = 1080; static const int _riverLogoMobileHeight = 1080;
/// Fraction de la hauteur de l'image où se termine visuellement le slogan (0 = haut, 1 = bas). /// Fraction de la hauteur de l'image où se termine visuellement le slogan (0 = haut, 1 = bas).
static const double _sloganEndFraction = 0.42; static const double _sloganEndFraction = 0.42;
static const double _gapBelowSlogan = 12.0; static const double _gapBelowSlogan = 12.0;
@ -414,8 +388,7 @@ class _LoginPageState extends State<LoginScreen> with WidgetsBindingObserver {
final h = constraints.maxHeight; final h = constraints.maxHeight;
final w = constraints.maxWidth; final w = constraints.maxWidth;
final imageAspectRatio = _riverLogoMobileHeight / _riverLogoMobileWidth; final imageAspectRatio = _riverLogoMobileHeight / _riverLogoMobileWidth;
final formTop = final formTop = w * imageAspectRatio * _sloganEndFraction + _gapBelowSlogan;
w * imageAspectRatio * _sloganEndFraction + _gapBelowSlogan;
return Stack( return Stack(
clipBehavior: Clip.none, clipBehavior: Clip.none,
children: [ children: [
@ -455,115 +428,95 @@ class _LoginPageState extends State<LoginScreen> with WidgetsBindingObserver {
children: [ children: [
Expanded( Expanded(
child: SingleChildScrollView( child: SingleChildScrollView(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 20),
horizontal: 24, vertical: 20),
child: ConstrainedBox( child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 400), constraints: const BoxConstraints(maxWidth: 400),
child: AutofillGroup( child: Form(
child: Form( key: _formKey,
key: _formKey, child: Column(
child: Column( mainAxisSize: MainAxisSize.min,
mainAxisSize: MainAxisSize.min, children: [
children: [ const SizedBox(height: 16),
const SizedBox(height: 16), CustomAppTextField(
CustomAppTextField( controller: _emailController,
controller: _emailController, labelText: 'Email',
labelText: 'Email', showLabel: false,
showLabel: false, hintText: 'Votre adresse email',
hintText: 'Votre adresse email', validator: _validateEmail,
keyboardType: TextInputType.emailAddress, style: CustomAppTextFieldStyle.lavande,
autofillHints: const [ fieldHeight: 48,
AutofillHints.username, fieldWidth: double.infinity,
AutofillHints.email, ),
], const SizedBox(height: 12),
textInputAction: TextInputAction.next, CustomAppTextField(
validator: _validateEmail, controller: _passwordController,
style: CustomAppTextFieldStyle.lavande, labelText: 'Mot de passe',
fieldHeight: 48, showLabel: false,
fieldWidth: double.infinity, hintText: 'Votre mot de passe',
), obscureText: true,
const SizedBox(height: 12), validator: _validatePassword,
CustomAppTextField( style: CustomAppTextFieldStyle.jaune,
controller: _passwordController, fieldHeight: 48,
labelText: 'Mot de passe', fieldWidth: double.infinity,
showLabel: false, ),
hintText: 'Votre mot de passe', if (_errorMessage != null) ...[
obscureText: true, const SizedBox(height: 12),
autofillHints: const [ Container(
AutofillHints.password padding: const EdgeInsets.all(12),
], decoration: BoxDecoration(
textInputAction: TextInputAction.done, color: Colors.red.shade50,
onFieldSubmitted: _handlePasswordSubmitted, borderRadius: BorderRadius.circular(10),
validator: _validatePassword, border: Border.all(color: Colors.red.shade300),
style: CustomAppTextFieldStyle.jaune, ),
fieldHeight: 48, child: Row(
fieldWidth: double.infinity, children: [
), Icon(Icons.error_outline, color: Colors.red.shade700, size: 20),
if (_errorMessage != null) ...[ const SizedBox(width: 10),
const SizedBox(height: 12), Expanded(
Container( child: Text(
padding: const EdgeInsets.all(12), _errorMessage!,
decoration: BoxDecoration( style: GoogleFonts.merienda(fontSize: 12, color: Colors.red.shade700),
color: Colors.red.shade50, ),
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: Colors.red.shade300),
),
child: Row(
children: [
Icon(Icons.error_outline,
color: Colors.red.shade700,
size: 20),
const SizedBox(width: 10),
Expanded(
child: Text(
_errorMessage!,
style: GoogleFonts.merienda(
fontSize: 12,
color: Colors.red.shade700),
),
),
],
),
),
],
const SizedBox(height: 12),
_isLoading
? const CircularProgressIndicator()
: ImageButton(
bg: 'assets/images/bg_green.png',
width: double.infinity,
height: 44,
text: 'Se connecter',
textColor: const Color(0xFF2D6A4F),
onPressed: _handleLogin,
),
const SizedBox(height: 12),
TextButton(
onPressed: () {/* TODO */},
child: Text(
'Mot de passe oublié ?',
style: GoogleFonts.merienda(
fontSize: 14,
color: const Color(0xFF2D6A4F),
decoration: TextDecoration.underline,
),
),
),
TextButton(
onPressed: () =>
context.go('/register-choice'),
child: Text(
'Créer un compte',
style: GoogleFonts.merienda(
fontSize: 16,
color: const Color(0xFF2D6A4F),
decoration: TextDecoration.underline,
),
),
),
],
), ),
],
),
),
],
const SizedBox(height: 12),
_isLoading
? const CircularProgressIndicator()
: ImageButton(
bg: 'assets/images/bg_green.png',
width: double.infinity,
height: 44,
text: 'Se connecter',
textColor: const Color(0xFF2D6A4F),
onPressed: _handleLogin,
),
const SizedBox(height: 12),
TextButton(
onPressed: () { /* TODO */ },
child: Text(
'Mot de passe oublié ?',
style: GoogleFonts.merienda(
fontSize: 14,
color: const Color(0xFF2D6A4F),
decoration: TextDecoration.underline,
),
),
),
TextButton(
onPressed: () => context.go('/register-choice'),
child: Text(
'Créer un compte',
style: GoogleFonts.merienda(
fontSize: 16,
color: const Color(0xFF2D6A4F),
decoration: TextDecoration.underline,
),
),
),
],
), ),
), ),
), ),
@ -580,17 +533,12 @@ class _LoginPageState extends State<LoginScreen> with WidgetsBindingObserver {
text: 'Contact support', text: 'Contact support',
fontSize: 11, fontSize: 11,
onTap: () async { onTap: () async {
final uri = Uri( final uri = Uri(scheme: 'mailto', path: 'support@supernounou.local');
scheme: 'mailto',
path: 'support@supernounou.local');
if (await canLaunchUrl(uri)) { if (await canLaunchUrl(uri)) {
await launchUrl(uri); await launchUrl(uri);
} else if (context.mounted) { } else if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar( ScaffoldMessenger.of(context).showSnackBar(
SnackBar( SnackBar(content: Text('Impossible d\'ouvrir le client mail', style: GoogleFonts.merienda())),
content: Text(
'Impossible d\'ouvrir le client mail',
style: GoogleFonts.merienda())),
); );
} }
}, },
@ -759,4 +707,4 @@ class _FooterLink extends StatelessWidget {
), ),
); );
} }
} }

View File

@ -10,7 +10,6 @@ enum CustomAppTextFieldStyle {
class CustomAppTextField extends StatefulWidget { class CustomAppTextField extends StatefulWidget {
final TextEditingController controller; final TextEditingController controller;
final FocusNode? focusNode;
final String labelText; final String labelText;
final String hintText; final String hintText;
final double fieldWidth; final double fieldWidth;
@ -27,14 +26,10 @@ class CustomAppTextField extends StatefulWidget {
final double labelFontSize; final double labelFontSize;
final double inputFontSize; final double inputFontSize;
final bool showLabel; final bool showLabel;
final Iterable<String>? autofillHints;
final TextInputAction? textInputAction;
final ValueChanged<String>? onFieldSubmitted;
const CustomAppTextField({ const CustomAppTextField({
super.key, super.key,
required this.controller, required this.controller,
this.focusNode,
required this.labelText, required this.labelText,
this.showLabel = true, this.showLabel = true,
this.hintText = '', this.hintText = '',
@ -51,9 +46,6 @@ class CustomAppTextField extends StatefulWidget {
this.suffixIcon, this.suffixIcon,
this.labelFontSize = 18.0, this.labelFontSize = 18.0,
this.inputFontSize = 18.0, this.inputFontSize = 18.0,
this.autofillHints,
this.textInputAction,
this.onFieldSubmitted,
}); });
@override @override
@ -76,7 +68,7 @@ class _CustomAppTextFieldState extends State<CustomAppTextField> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
const double fontHeightMultiplier = 1.2; const double fontHeightMultiplier = 1.2;
const double internalVerticalPadding = 16.0; const double internalVerticalPadding = 16.0;
final double dynamicFieldHeight = widget.fieldHeight; final double dynamicFieldHeight = widget.fieldHeight;
return Column( return Column(
@ -98,7 +90,7 @@ class _CustomAppTextFieldState extends State<CustomAppTextField> {
width: widget.fieldWidth, width: widget.fieldWidth,
height: dynamicFieldHeight, height: dynamicFieldHeight,
child: Stack( child: Stack(
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
children: [ children: [
Positioned.fill( Positioned.fill(
child: Image.asset( child: Image.asset(
@ -107,49 +99,40 @@ class _CustomAppTextFieldState extends State<CustomAppTextField> {
), ),
), ),
Padding( Padding(
padding: padding: const EdgeInsets.symmetric(horizontal: 18.0, vertical: 8.0),
const EdgeInsets.symmetric(horizontal: 18.0, vertical: 8.0),
child: TextFormField( child: TextFormField(
controller: widget.controller, controller: widget.controller,
focusNode: widget.focusNode,
obscureText: widget.obscureText, obscureText: widget.obscureText,
keyboardType: widget.keyboardType, keyboardType: widget.keyboardType,
autofillHints: widget.autofillHints,
textInputAction: widget.textInputAction,
onFieldSubmitted: widget.onFieldSubmitted,
enabled: widget.enabled, enabled: widget.enabled,
readOnly: widget.readOnly, readOnly: widget.readOnly,
onTap: widget.onTap, onTap: widget.onTap,
style: GoogleFonts.merienda( style: GoogleFonts.merienda(
fontSize: widget.inputFontSize, fontSize: widget.inputFontSize,
color: widget.enabled ? Colors.black87 : Colors.grey), color: widget.enabled ? Colors.black87 : Colors.grey
),
validator: widget.validator ?? validator: widget.validator ??
(value) { (value) {
if (!widget.enabled || widget.readOnly) return null; if (!widget.enabled || widget.readOnly) return null;
if (widget.isRequired && if (widget.isRequired && (value == null || value.isEmpty)) {
(value == null || value.isEmpty)) { return 'Ce champ est obligatoire';
return 'Ce champ est obligatoire'; }
} return null;
return null; },
},
decoration: InputDecoration( decoration: InputDecoration(
hintText: widget.hintText, hintText: widget.hintText,
hintStyle: GoogleFonts.merienda( hintStyle: GoogleFonts.merienda(fontSize: widget.inputFontSize, color: Colors.black54.withOpacity(0.7)),
fontSize: widget.inputFontSize,
color: Colors.black54.withOpacity(0.7)),
border: InputBorder.none, border: InputBorder.none,
contentPadding: EdgeInsets.zero, contentPadding: EdgeInsets.zero,
suffixIcon: widget.suffixIcon != null suffixIcon: widget.suffixIcon != null
? Padding( ? Padding(
padding: const EdgeInsets.only(right: 0.0), padding: const EdgeInsets.only(right: 0.0),
child: Icon(widget.suffixIcon, child: Icon(widget.suffixIcon, color: Colors.black54, size: widget.inputFontSize * 1.1),
color: Colors.black54,
size: widget.inputFontSize * 1.1),
) )
: null, : null,
isDense: true, isDense: true,
), ),
textAlignVertical: TextAlignVertical.center, textAlignVertical: TextAlignVertical.center,
), ),
), ),
], ],
@ -158,4 +141,4 @@ class _CustomAppTextFieldState extends State<CustomAppTextField> {
], ],
); );
} }
} }

View File

@ -23,38 +23,26 @@ class ImageButton extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SizedBox( return MouseRegion(
width: width, cursor: SystemMouseCursors.click,
height: height, child: GestureDetector(
child: Semantics( onTap: onPressed,
button: true, child: Container(
label: text, width: width,
child: MouseRegion( height: height,
cursor: SystemMouseCursors.click, decoration: BoxDecoration(
child: TextButton( image: DecorationImage(
onPressed: onPressed, image: AssetImage(bg),
style: TextButton.styleFrom( fit: BoxFit.fill,
padding: EdgeInsets.zero,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
shape:
const RoundedRectangleBorder(borderRadius: BorderRadius.zero),
), ),
child: Ink( ),
decoration: BoxDecoration( child: Center(
image: DecorationImage( child: Text(
image: AssetImage(bg), text,
fit: BoxFit.fill, style: GoogleFonts.merienda(
), color: textColor,
), fontSize: fontSize, // Utilisation du paramètre
child: Center( fontWeight: FontWeight.bold,
child: Text(
text,
style: GoogleFonts.merienda(
color: textColor,
fontSize: fontSize, // Utilisation du paramètre
fontWeight: FontWeight.bold,
),
),
), ),
), ),
), ),
@ -62,4 +50,4 @@ class ImageButton extends StatelessWidget {
), ),
); );
} }
} }