diff --git a/frontend/lib/models/user_registration_data.dart b/frontend/lib/models/user_registration_data.dart index e418e7d..bedd247 100644 --- a/frontend/lib/models/user_registration_data.dart +++ b/frontend/lib/models/user_registration_data.dart @@ -30,6 +30,7 @@ class ParentData { class ChildData { static const Object _unsetImage = Object(); static const Object _unsetImageBytes = Object(); + static const Object _unsetExistingPhotoUrl = Object(); String firstName; String lastName; @@ -75,7 +76,7 @@ class ChildData { Object? imageBytes = _unsetImageBytes, CardColorVertical? cardColor, String? repriseChildId, - String? existingPhotoUrl, + Object? existingPhotoUrl = _unsetExistingPhotoUrl, }) { return ChildData( firstName: firstName ?? this.firstName, @@ -90,7 +91,9 @@ class ChildData { identical(imageBytes, _unsetImageBytes) ? this.imageBytes : imageBytes as Uint8List?, cardColor: cardColor ?? this.cardColor, repriseChildId: repriseChildId ?? this.repriseChildId, - existingPhotoUrl: existingPhotoUrl ?? this.existingPhotoUrl, + existingPhotoUrl: identical(existingPhotoUrl, _unsetExistingPhotoUrl) + ? this.existingPhotoUrl + : existingPhotoUrl as String?, ); } } diff --git a/frontend/lib/screens/auth/parent_register_step3_screen.dart b/frontend/lib/screens/auth/parent_register_step3_screen.dart index e13b3a9..ec5ed5d 100644 --- a/frontend/lib/screens/auth/parent_register_step3_screen.dart +++ b/frontend/lib/screens/auth/parent_register_step3_screen.dart @@ -166,7 +166,11 @@ class _ParentRegisterStep3ScreenState extends State { if (await f.exists()) file = f; } catch (_) {} } - final updatedChild = oldChild.copyWith(imageBytes: bytes, imageFile: file); + final updatedChild = oldChild.copyWith( + imageBytes: bytes, + imageFile: file, + existingPhotoUrl: null, + ); registrationData.updateChild(childIndex, updatedChild); } } @@ -306,7 +310,7 @@ class _ParentRegisterStep3ScreenState extends State { onClearImage: () => setState(() { final c = registrationData.children[index]; registrationData.updateChild( - index, c.copyWith(imageFile: null, imageBytes: null)); + index, c.copyWith(imageFile: null, imageBytes: null, existingPhotoUrl: null)); }), onDateSelect: () => _selectDate(context, index, registrationData), onFirstNameChanged: (value) => setState(() { @@ -414,7 +418,7 @@ class _ParentRegisterStep3ScreenState extends State { onClearImage: () => setState(() { final c = registrationData.children[index]; registrationData.updateChild( - index, c.copyWith(imageFile: null, imageBytes: null)); + index, c.copyWith(imageFile: null, imageBytes: null, existingPhotoUrl: null)); }), onDateSelect: () => _selectDate(context, index, registrationData), onFirstNameChanged: (value) => setState(() { diff --git a/frontend/lib/utils/reprise_mapper.dart b/frontend/lib/utils/reprise_mapper.dart index a44947a..6720f9f 100644 --- a/frontend/lib/utils/reprise_mapper.dart +++ b/frontend/lib/utils/reprise_mapper.dart @@ -37,12 +37,15 @@ class RepriseMapper { ? isoToDdMmYyyy(e.dueDate) : isoToDdMmYyyy(e.birthDate); final photo = e.photoUrl?.trim(); + final hasPhoto = photo != null && photo.isNotEmpty; return ChildData( firstName: e.firstName ?? '', lastName: e.lastName ?? '', dob: dob, genre: e.gender ?? '', - photoConsent: e.consentPhoto, + // Inscription initiale exigeait la coche pour envoyer la photo ; le back + // ne persistait pas toujours consent_photo — on pré-coche si photo en base. + photoConsent: e.consentPhoto || hasPhoto, multipleBirth: e.estMultiple, isUnbornChild: isUnborn, cardColor: _childCardColors[index % _childCardColors.length], diff --git a/frontend/lib/widgets/child_card_widget.dart b/frontend/lib/widgets/child_card_widget.dart index 1afbf6e..4ff744f 100644 --- a/frontend/lib/widgets/child_card_widget.dart +++ b/frontend/lib/widgets/child_card_widget.dart @@ -1,4 +1,5 @@ import 'dart:math' as math; +import 'dart:io'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -20,7 +21,7 @@ bool _hasChildPhoto(ChildData c) { return registrationPhotoSlotHasImage( imageBytes: c.imageBytes, imageFile: c.imageFile, - imagePathOrAsset: null, + imagePathOrAsset: c.existingPhotoUrl, ); } @@ -33,6 +34,20 @@ Widget _buildChildPhotoImage(ChildData c, {required BoxFit fit}) { if (f != null) { return kIsWeb ? Image.network(f.path, fit: fit) : Image.file(f, fit: fit); } + final url = c.existingPhotoUrl?.trim(); + if (url != null && url.isNotEmpty) { + if (url.startsWith('http://') || url.startsWith('https://')) { + return Image.network(url, fit: fit); + } + if (!kIsWeb) { + try { + final file = File(url); + if (file.existsSync()) { + return Image.file(file, fit: fit); + } + } catch (_) {} + } + } return Image.asset('assets/images/photo.png', fit: BoxFit.contain); } @@ -221,6 +236,7 @@ class _ChildCardWidgetState extends State { scaleFactor: scaleFactor, imageBytes: widget.childData.imageBytes, imageFile: widget.childData.imageFile, + imagePathOrAsset: widget.childData.existingPhotoUrl, onTapPick: !config.isReadonly ? widget.onPickImage : null, onClear: !config.isReadonly ? widget.onClearImage : null, baseShadowColor: baseCardColorForShadow, diff --git a/frontend/lib/widgets/registration_photo_slot.dart b/frontend/lib/widgets/registration_photo_slot.dart index 7dde753..2338ef9 100644 --- a/frontend/lib/widgets/registration_photo_slot.dart +++ b/frontend/lib/widgets/registration_photo_slot.dart @@ -71,6 +71,9 @@ class RegistrationPhotoSlot extends StatelessWidget { if (p.startsWith('assets/')) { return Image.asset(p, fit: fit); } + if (p.startsWith('http://') || p.startsWith('https://')) { + return Image.network(p, fit: fit); + } if (!kIsWeb) { try { final file = File(p);