feat(ui): Ajout des icônes de croix rouge et grise pour la suppression des cartes enfants

This commit is contained in:
Julien Martin 2025-05-12 12:21:05 +02:00
parent 1496f7f174
commit 03712bd99b
3 changed files with 22 additions and 14 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

View File

@ -43,6 +43,9 @@ class _ParentRegisterStep3ScreenState extends State<ParentRegisterStep3Screen> {
CardColorVertical.blue, CardColorVertical.blue,
]; ];
// Garder une trace des couleurs déjà utilisées
final Set<CardColorVertical> _usedColors = {};
// Utilisation de GlobalKey pour les cartes enfants si validation complexe future // Utilisation de GlobalKey pour les cartes enfants si validation complexe future
// Map<int, GlobalKey<FormState>> _childFormKeys = {}; // Map<int, GlobalKey<FormState>> _childFormKeys = {};
@ -50,6 +53,10 @@ class _ParentRegisterStep3ScreenState extends State<ParentRegisterStep3Screen> {
void initState() { void initState() {
super.initState(); super.initState();
_registrationData = widget.registrationData; _registrationData = widget.registrationData;
// Initialiser les couleurs utilisées avec les enfants existants
for (var child in _registrationData.children) {
_usedColors.add(child.cardColor);
}
// S'il n'y a pas d'enfant, en ajouter un automatiquement avec des données générées // S'il n'y a pas d'enfant, en ajouter un automatiquement avec des données générées
if (_registrationData.children.isEmpty) { if (_registrationData.children.isEmpty) {
_addChild(); _addChild();
@ -83,22 +90,24 @@ class _ParentRegisterStep3ScreenState extends State<ParentRegisterStep3Screen> {
void _addChild() { void _addChild() {
setState(() { setState(() {
bool isUnborn = DataGenerator.boolean(); bool isUnborn = DataGenerator.boolean();
// Déterminer la couleur de la carte pour le nouvel enfant
final cardColor = _childCardColors[_registrationData.children.length % _childCardColors.length]; // Trouver la première couleur non utilisée
CardColorVertical cardColor = _childCardColors.firstWhere(
(color) => !_usedColors.contains(color),
orElse: () => _childCardColors[0], // Fallback sur la première couleur si toutes sont utilisées
);
final newChild = ChildData( final newChild = ChildData(
lastName: _registrationData.parent1.lastName, // Hérite du nom de famille du parent 1 lastName: _registrationData.parent1.lastName,
firstName: DataGenerator.firstName(), firstName: DataGenerator.firstName(),
dob: DataGenerator.dob(isUnborn: isUnborn), dob: DataGenerator.dob(isUnborn: isUnborn),
isUnbornChild: isUnborn, isUnbornChild: isUnborn,
photoConsent: DataGenerator.boolean(), photoConsent: DataGenerator.boolean(),
multipleBirth: DataGenerator.boolean(), multipleBirth: DataGenerator.boolean(),
cardColor: cardColor, // Assigner la couleur cardColor: cardColor,
// imageFile: null, // Pas d'image générée pour l'instant
); );
_registrationData.addChild(newChild); _registrationData.addChild(newChild);
// Ajouter une clé de formulaire si nécessaire _usedColors.add(cardColor);
// _childFormKeys[_registrationData.children.length - 1] = GlobalKey<FormState>();
}); });
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
_scrollListener(); _scrollListener();
@ -111,10 +120,8 @@ class _ParentRegisterStep3ScreenState extends State<ParentRegisterStep3Screen> {
void _removeChild(int index) { void _removeChild(int index) {
if (_registrationData.children.length > 1 && index >= 0 && index < _registrationData.children.length) { if (_registrationData.children.length > 1 && index >= 0 && index < _registrationData.children.length) {
setState(() { setState(() {
// Ne pas retirer la couleur de _usedColors pour éviter sa réutilisation
_registrationData.children.removeAt(index); _registrationData.children.removeAt(index);
// Supprimer aussi la clé de formulaire associée si utilisée
// _childFormKeys.remove(index);
// Il faudrait aussi décaler les clés des enfants suivants si on utilise les index comme clés de map
}); });
WidgetsBinding.instance.addPostFrameCallback((_) => _scrollListener()); WidgetsBinding.instance.addPostFrameCallback((_) => _scrollListener());
} }
@ -465,10 +472,11 @@ class _ChildCardWidgetState extends State<_ChildCardWidget> {
child: InkWell( child: InkWell(
onTap: widget.onRemove, onTap: widget.onRemove,
customBorder: const CircleBorder(), customBorder: const CircleBorder(),
child: Container( child: Image.asset(
padding: const EdgeInsets.all(4), 'images/red_cross2.png',
decoration: BoxDecoration(color: Colors.red.withOpacity(0.8), shape: BoxShape.circle), width: 36,
child: const Icon(Icons.close, color: Colors.white, size: 18), height: 36,
fit: BoxFit.contain,
), ),
), ),
), ),