Files
jmartinandCursor 7f554e2ba3 fix(#211): overflow pastilles bandeau + couple plus centré
Les pastilles se réduisent si la fenêtre est étroite ; le sélecteur couple est poussé vers le centre.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-11 10:44:04 +02:00

350 lines
10 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:p_tits_pas/services/auth_service.dart';
import 'package:p_tits_pas/widgets/image_button.dart';
import 'package:p_tits_pas/widgets/quotidien/quotidien_theme.dart';
/// Bandeau quotidien pastel : logo · [contexte couple] · pastilles · menu user.
/// Réutilisable parent (#166) et AM (#169) ; couple compact (#211).
class QuotidienBandeau extends StatelessWidget {
final QuotidienNavSection selectedSection;
final ValueChanged<QuotidienNavSection> onSectionSelected;
final String userDisplayName;
final String? userEmail;
/// Sélecteur de couple compact, juste après le logo (~280 px).
final Widget? contextSelector;
final VoidCallback? onProfileTap;
final VoidCallback? onSearchAmTap;
final VoidCallback? onSettingsTap;
final VoidCallback? onLogout;
static const double contextSelectorMaxWidth = 280;
const QuotidienBandeau({
super.key,
required this.selectedSection,
required this.onSectionSelected,
required this.userDisplayName,
this.userEmail,
this.contextSelector,
this.onProfileTap,
this.onSearchAmTap,
this.onSettingsTap,
this.onLogout,
});
@override
Widget build(BuildContext context) {
// 3 zones : gauche (logo + couple vers le centre) · pastilles · menu.
// Les Expanded gauche/droite équilibrent le centrage des pastilles.
return Padding(
padding: const EdgeInsets.fromLTRB(16, 12, 16, 8),
child: Row(
children: [
Expanded(
child: Row(
children: [
Image.asset(
QuotidienTheme.logoAsset,
height: 44,
fit: BoxFit.contain,
),
if (contextSelector != null) ...[
const SizedBox(width: 16),
Flexible(
child: Align(
// Pousse le couple vers le centre du bandeau.
alignment: Alignment.centerRight,
child: ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: contextSelectorMaxWidth,
),
child: contextSelector!,
),
),
),
],
],
),
),
const SizedBox(width: 8),
Flexible(
flex: 2,
child: Center(
child: _NavPills(
selected: selectedSection,
onSelected: onSectionSelected,
),
),
),
const SizedBox(width: 8),
Expanded(
child: Align(
alignment: Alignment.centerRight,
child: _UserMenu(
displayName: userDisplayName,
email: userEmail,
onProfileTap: onProfileTap,
onSearchAmTap: onSearchAmTap,
onSettingsTap: onSettingsTap,
onLogout: onLogout,
),
),
),
],
),
);
}
}
class _NavPills extends StatelessWidget {
final QuotidienNavSection selected;
final ValueChanged<QuotidienNavSection> onSelected;
const _NavPills({
required this.selected,
required this.onSelected,
});
static const double _pillHeight = 46;
static const double _gap = 10;
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
final naturalW = _pillHeight * QuotidienTheme.pillAspectRatio;
final naturalTotal = 3 * naturalW + 2 * _gap;
final maxW = constraints.maxWidth;
// Réduit proportionnellement si la fenêtre est trop étroite
// (évite l’overflow jaune/noir sur les pastilles).
final scale = maxW.isFinite && maxW > 0 && maxW < naturalTotal
? (maxW / naturalTotal).clamp(0.55, 1.0)
: 1.0;
final h = _pillHeight * scale;
final w = naturalW * scale;
final g = _gap * scale;
final fontSize = (14 * scale).clamp(10.0, 14.0);
return Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
_pill(
label: 'Cahier de liaison',
section: QuotidienNavSection.liaison,
width: w,
height: h,
fontSize: fontSize,
),
SizedBox(width: g),
_pill(
label: 'Agenda',
section: QuotidienNavSection.agenda,
width: w,
height: h,
fontSize: fontSize,
),
SizedBox(width: g),
_pill(
label: 'Contrat',
section: QuotidienNavSection.contrat,
width: w,
height: h,
fontSize: fontSize,
),
],
);
},
);
}
Widget _pill({
required String label,
required QuotidienNavSection section,
required double width,
required double height,
required double fontSize,
}) {
final active = selected == section;
return ImageButton(
bg: QuotidienTheme.pillAssetFor(section),
bgOpacity: active ? 1.0 : QuotidienTheme.pillInactiveOpacity,
width: width,
height: height,
text: label,
textColor: QuotidienTheme.ink,
fontSize: fontSize,
onPressed: () => onSelected(section),
);
}
}
class _UserMenu extends StatelessWidget {
final String displayName;
final String? email;
final VoidCallback? onProfileTap;
final VoidCallback? onSearchAmTap;
final VoidCallback? onSettingsTap;
final VoidCallback? onLogout;
const _UserMenu({
required this.displayName,
this.email,
this.onProfileTap,
this.onSearchAmTap,
this.onSettingsTap,
this.onLogout,
});
@override
Widget build(BuildContext context) {
final shortName = displayName.trim().isEmpty ? 'Compte' : displayName.trim();
const double pillHeight = 46;
const double pillWidth = pillHeight * QuotidienTheme.pillAspectRatio;
return PopupMenuButton<String>(
tooltip: 'Menu utilisateur',
offset: const Offset(0, pillHeight + 4),
color: QuotidienTheme.ivory,
elevation: 3,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
side: BorderSide(color: QuotidienTheme.lavender.withOpacity(0.6)),
),
onSelected: (value) async {
switch (value) {
case 'profile':
onProfileTap?.call();
break;
case 'search_am':
onSearchAmTap?.call();
break;
case 'settings':
onSettingsTap?.call();
break;
case 'logout':
await _confirmLogout(context);
break;
}
},
itemBuilder: (context) => [
if (email != null && email!.trim().isNotEmpty)
PopupMenuItem(
enabled: false,
child: Text(
email!,
style: TextStyle(color: QuotidienTheme.muted, fontSize: 12),
),
),
const PopupMenuDivider(),
const PopupMenuItem(
value: 'profile',
child: ListTile(
dense: true,
contentPadding: EdgeInsets.zero,
leading: Icon(Icons.person_outline, size: 20),
title: Text('Profil'),
),
),
if (onSearchAmTap != null)
const PopupMenuItem(
value: 'search_am',
child: ListTile(
dense: true,
contentPadding: EdgeInsets.zero,
leading: Icon(Icons.search, size: 20),
title: Text('Recherche AM'),
),
),
const PopupMenuItem(
value: 'settings',
child: ListTile(
dense: true,
contentPadding: EdgeInsets.zero,
leading: Icon(Icons.settings_outlined, size: 20),
title: Text('Paramètres'),
),
),
const PopupMenuDivider(),
const PopupMenuItem(
value: 'logout',
child: ListTile(
dense: true,
contentPadding: EdgeInsets.zero,
leading: Icon(Icons.logout, size: 20),
title: Text('Déconnexion'),
),
),
],
// Même pastille « dessinée » que la nav, teinte violet pastel charte.
child: Container(
width: pillWidth,
height: pillHeight,
padding: const EdgeInsets.symmetric(horizontal: 14),
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(QuotidienTheme.pillLavenderAsset),
fit: BoxFit.fill,
),
),
child: Row(
children: [
const Icon(
Icons.person_outline,
size: 20,
color: QuotidienTheme.ink,
),
const SizedBox(width: 6),
Expanded(
child: Text(
shortName,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: GoogleFonts.merienda(
fontSize: 13,
fontWeight: FontWeight.bold,
color: QuotidienTheme.ink,
),
),
),
const Icon(
Icons.keyboard_arrow_down,
size: 18,
color: QuotidienTheme.ink,
),
],
),
),
);
}
Future<void> _confirmLogout(BuildContext context) async {
final ok = await showDialog<bool>(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('Déconnexion'),
content: const Text('Voulez-vous vraiment vous déconnecter ?'),
actions: [
TextButton(
onPressed: () => Navigator.of(ctx).pop(false),
child: const Text('Annuler'),
),
TextButton(
onPressed: () => Navigator.of(ctx).pop(true),
child: const Text('Déconnexion'),
),
],
),
);
if (ok != true) return;
onLogout?.call();
await AuthService.logout();
if (context.mounted) {
context.go('/login');
}
}
}