feat(#140): fiches admin famille — IdentityBlock, parsing enfants et avatars web

Extrait IdentityBlock réutilisable, aligne les modales parent/enfant sur le style validation, corrige le parsing parentChildren et les URLs /uploads en Flutter web.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-21 17:42:00 +02:00
co-authored by Cursor
parent 1dddc67933
commit 8494341b56
11 changed files with 1075 additions and 458 deletions
@@ -32,6 +32,12 @@ class _AdminChildDetailModalState extends State<AdminChildDetailModal> {
static const _statuses = ['a_naitre', 'actif', 'scolarise'];
static const _genders = ['H', 'F', 'Autre'];
static const _labelStyle = TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Colors.black87,
);
@override
void initState() {
super.initState();
@@ -41,7 +47,7 @@ class _AdminChildDetailModalState extends State<AdminChildDetailModal> {
_birthCtrl = TextEditingController(text: e.birthDate ?? '');
_dueCtrl = TextEditingController(text: e.dueDate ?? '');
_status = _statuses.contains(e.status) ? e.status : 'actif';
_gender = _genders.contains(e.gender) ? e.gender! : 'H';
_gender = _normalizeGender(e.gender);
_consentPhoto = e.consentPhoto;
_isMultiple = e.isMultiple;
for (final c in [_prenomCtrl, _nomCtrl, _birthCtrl, _dueCtrl]) {
@@ -57,6 +63,13 @@ class _AdminChildDetailModalState extends State<AdminChildDetailModal> {
super.dispose();
}
static String _normalizeGender(String? raw) {
final g = (raw ?? '').trim();
if (g == 'M') return 'H';
if (_genders.contains(g)) return g;
return 'H';
}
void _markDirty() {
if (!_dirty) setState(() => _dirty = true);
}
@@ -72,7 +85,8 @@ class _AdminChildDetailModalState extends State<AdminChildDetailModal> {
'last_name': _nomCtrl.text.trim(),
'status': _status,
'gender': _gender,
if (_birthCtrl.text.trim().isNotEmpty) 'birth_date': _birthCtrl.text.trim(),
if (_birthCtrl.text.trim().isNotEmpty)
'birth_date': _birthCtrl.text.trim(),
if (_dueCtrl.text.trim().isNotEmpty) 'due_date': _dueCtrl.text.trim(),
'consent_photo': _consentPhoto,
'is_multiple': _isMultiple,
@@ -96,124 +110,215 @@ class _AdminChildDetailModalState extends State<AdminChildDetailModal> {
}
}
String _parentsLine() {
final names = widget.enfant.parentLinks
.map((l) {
final n = (l.parentName ?? '').trim();
return n.isNotEmpty ? n : 'Parent rattaché';
})
.where((s) => s.isNotEmpty)
.toList();
if (names.isEmpty) return '';
return names.join(', ');
}
@override
Widget build(BuildContext context) {
final parents = widget.enfant.parentLinks
.map((l) => l.parentName ?? l.parentId)
.where((s) => s.isNotEmpty)
.join(', ');
final parents = _parentsLine();
final showDueDate = _status == 'a_naitre';
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 560, maxHeight: 640),
child: Padding(
padding: const EdgeInsets.all(18),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
Expanded(
child: Text(
widget.enfant.fullName,
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w700),
child: SizedBox(
width: 480,
child: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: 640),
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisSize: MainAxisSize.min,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.enfant.fullName,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w700,
),
),
if (parents.isNotEmpty) ...[
const SizedBox(height: 4),
Text(
'Responsables : $parents',
style: const TextStyle(
fontSize: 13,
color: Colors.black54,
),
),
],
],
),
),
IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: const Icon(Icons.close),
tooltip: 'Fermer',
),
],
),
const SizedBox(height: 12),
const Divider(height: 1),
const SizedBox(height: 12),
Flexible(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: _labeledField(
'Prénom',
TextField(
controller: _prenomCtrl,
decoration: _decoration(),
),
),
),
const SizedBox(width: 12),
Expanded(
child: _labeledField(
'Nom',
TextField(
controller: _nomCtrl,
decoration: _decoration(),
),
),
),
],
),
const SizedBox(height: 12),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: _labeledDropdown(
'Statut',
_status,
_statuses
.map((s) => MapEntry(s, _statusLabel(s)))
.toList(),
(v) => setState(() {
_status = v;
_dirty = true;
}),
),
),
const SizedBox(width: 12),
Expanded(
child: _labeledDropdown(
'Genre',
_gender,
_genders
.map((g) => MapEntry(g, _genderLabel(g)))
.toList(),
(v) => setState(() {
_gender = v;
_dirty = true;
}),
),
),
],
),
const SizedBox(height: 12),
if (showDueDate)
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: _labeledField(
'Date de naissance',
TextField(
controller: _birthCtrl,
decoration:
_decoration(hint: 'AAAA-MM-JJ'),
),
),
),
const SizedBox(width: 12),
Expanded(
child: _labeledField(
'Date prévue',
TextField(
controller: _dueCtrl,
decoration:
_decoration(hint: 'AAAA-MM-JJ'),
),
),
),
],
)
else
_labeledField(
'Date de naissance',
TextField(
controller: _birthCtrl,
decoration: _decoration(hint: 'AAAA-MM-JJ'),
),
),
const SizedBox(height: 16),
_switchRow(
'Consentement photo',
_consentPhoto,
(v) => setState(() {
_consentPhoto = v;
_dirty = true;
}),
),
_switchRow(
'Naissance multiple',
_isMultiple,
(v) => setState(() {
_isMultiple = v;
_dirty = true;
}),
),
],
),
),
IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: const Icon(Icons.close),
),
],
),
if (parents.isNotEmpty)
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Text('Responsables : $parents', style: const TextStyle(color: Colors.black54)),
),
const Divider(),
Expanded(
child: SingleChildScrollView(
child: Column(
children: [
_rowField('Prénom', TextField(controller: _prenomCtrl, decoration: _decoration())),
_rowField('Nom', TextField(controller: _nomCtrl, decoration: _decoration())),
_rowDropdown(
'Statut',
_status,
_statuses.map((s) => MapEntry(s, _statusLabel(s))).toList(),
(v) => setState(() {
_status = v;
_dirty = true;
}),
),
_rowDropdown(
'Genre',
_gender,
_genders.map((g) => MapEntry(g, g)).toList(),
(v) => setState(() {
_gender = v;
_dirty = true;
}),
),
_rowField(
'Date naissance',
TextField(
controller: _birthCtrl,
decoration: _decoration(hint: 'AAAA-MM-JJ'),
),
),
_rowField(
'Date prévue',
TextField(
controller: _dueCtrl,
decoration: _decoration(hint: 'AAAA-MM-JJ'),
),
),
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: const Text('Consentement photo'),
value: _consentPhoto,
onChanged: (v) => setState(() {
_consentPhoto = v;
_dirty = true;
}),
),
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: const Text('Naissance multiple'),
value: _isMultiple,
onChanged: (v) => setState(() {
_isMultiple = v;
_dirty = true;
}),
),
],
),
const SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Fermer'),
),
const SizedBox(width: 8),
ElevatedButton.icon(
onPressed: !_dirty || _saving ? null : _save,
icon: _saving
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Icon(Icons.save),
label: const Text('Sauvegarder'),
),
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Fermer'),
),
const SizedBox(width: 8),
ElevatedButton.icon(
onPressed: !_dirty || _saving ? null : _save,
icon: _saving
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Icon(Icons.save),
label: const Text('Sauvegarder'),
),
],
),
],
],
),
),
),
),
@@ -221,53 +326,62 @@ class _AdminChildDetailModalState extends State<AdminChildDetailModal> {
}
InputDecoration _decoration({String? hint}) {
return InputDecoration(isDense: true, border: const OutlineInputBorder(), hintText: hint);
}
Widget _rowField(String label, Widget field) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 120,
child: Padding(
padding: const EdgeInsets.only(top: 12),
child: Text(label, style: const TextStyle(fontWeight: FontWeight.w600)),
),
),
Expanded(child: field),
],
),
return InputDecoration(
isDense: true,
border: const OutlineInputBorder(),
hintText: hint,
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
);
}
Widget _rowDropdown(
Widget _labeledField(String label, Widget field) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(label, style: _labelStyle),
const SizedBox(height: 4),
field,
],
);
}
Widget _labeledDropdown(
String label,
String value,
List<MapEntry<String, String>> items,
ValueChanged<String> onChanged,
) {
final safeValue =
items.any((e) => e.key == value) ? value : items.first.key;
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(label, style: _labelStyle),
const SizedBox(height: 4),
DropdownButtonFormField<String>(
value: safeValue,
isExpanded: true,
decoration: _decoration(),
items: items
.map((e) => DropdownMenuItem(value: e.key, child: Text(e.value)))
.toList(),
onChanged: (v) {
if (v != null) onChanged(v);
},
),
],
);
}
Widget _switchRow(String label, bool value, ValueChanged<bool> onChanged) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 6),
padding: const EdgeInsets.symmetric(vertical: 4),
child: Row(
children: [
SizedBox(
width: 120,
child: Text(label, style: const TextStyle(fontWeight: FontWeight.w600)),
),
Expanded(
child: DropdownButtonFormField<String>(
value: items.any((e) => e.key == value) ? value : items.first.key,
decoration: _decoration(),
items: items
.map((e) => DropdownMenuItem(value: e.key, child: Text(e.value)))
.toList(),
onChanged: (v) {
if (v != null) onChanged(v);
},
),
Expanded(child: Text(label, style: _labelStyle)),
Switch(
value: value,
onChanged: onChanged,
),
],
),
@@ -286,4 +400,17 @@ class _AdminChildDetailModalState extends State<AdminChildDetailModal> {
return status;
}
}
String _genderLabel(String gender) {
switch (gender) {
case 'H':
return 'Garçon';
case 'F':
return 'Fille';
case 'Autre':
return 'Autre';
default:
return gender;
}
}
}