Files
afterwork/lib/presentation/widgets/image_preview_picker.dart
dahoud 92612abbd7 fix(chat): Correction race condition + Implémentation TODOs
## Corrections Critiques

### Race Condition - Statuts de Messages
- Fix : Les icônes de statut (✓, ✓✓, ✓✓ bleu) ne s'affichaient pas
- Cause : WebSocket delivery confirmations arrivaient avant messages locaux
- Solution : Pattern Optimistic UI dans chat_bloc.dart
  - Création message temporaire immédiate
  - Ajout à la liste AVANT requête HTTP
  - Remplacement par message serveur à la réponse
- Fichier : lib/presentation/state_management/chat_bloc.dart

## Implémentation TODOs (13/21)

### Social (social_header_widget.dart)
-  Copier lien du post dans presse-papiers
-  Partage natif via Share.share()
-  Dialogue de signalement avec 5 raisons

### Partage (share_post_dialog.dart)
-  Interface sélection d'amis avec checkboxes
-  Partage externe via Share API

### Média (media_upload_service.dart)
-  Parsing JSON réponse backend
-  Méthode deleteMedia() pour suppression
-  Génération miniature vidéo

### Posts (create_post_dialog.dart, edit_post_dialog.dart)
-  Extraction URL depuis uploads
-  Documentation chargement médias

### Chat (conversations_screen.dart)
-  Navigation vers notifications
-  ConversationSearchDelegate pour recherche

## Nouveaux Fichiers

### Configuration
- build-prod.ps1 : Script build production avec dart-define
- lib/core/constants/env_config.dart : Gestion environnements

### Documentation
- TODOS_IMPLEMENTED.md : Documentation complète TODOs

## Améliorations

### Architecture
- Refactoring injection de dépendances
- Amélioration routing et navigation
- Optimisation providers (UserProvider, FriendsProvider)

### UI/UX
- Amélioration thème et couleurs
- Optimisation animations
- Meilleure gestion erreurs

### Services
- Configuration API avec env_config
- Amélioration datasources (events, users)
- Optimisation modèles de données
2026-01-10 10:43:17 +00:00

119 lines
4.2 KiB
Dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
/// `ImagePreviewPicker` est un widget permettant à l'utilisateur de choisir une image depuis la galerie ou de prendre une photo.
/// Ce widget affiche un aperçu de l'image sélectionnée et gère l'interaction pour choisir une nouvelle image.
///
/// Arguments :
/// - `onImagePicked`: Un callback qui renvoie le fichier image sélectionné (ou null si aucune image n'est choisie).
class ImagePreviewPicker extends StatefulWidget {
const ImagePreviewPicker({required this.onImagePicked, super.key});
final void Function(File?) onImagePicked;
@override
_ImagePreviewPickerState createState() => _ImagePreviewPickerState();
}
class _ImagePreviewPickerState extends State<ImagePreviewPicker> {
File? _selectedImageFile;
/// Méthode pour ouvrir le modal de sélection d'image avec une animation.
Future<void> _pickImage() async {
// Log : Ouverture du modal de sélection d'image
debugPrint('Ouverture du modal de sélection d\'image');
final ImagePicker picker = ImagePicker();
// Affichage du modal de sélection d'image
final XFile? pickedFile = await showModalBottomSheet<XFile?>(
context: context,
builder: (BuildContext context) {
return SafeArea(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ListTile(
leading: const Icon(Icons.camera_alt),
title: const Text('Prendre une photo'),
onTap: () async {
Navigator.pop(context, await picker.pickImage(source: ImageSource.camera));
},
),
ListTile(
leading: const Icon(Icons.photo_library),
title: const Text('Choisir depuis la galerie'),
onTap: () async {
Navigator.pop(context, await picker.pickImage(source: ImageSource.gallery));
},
),
],
),
);
},
);
// Si un fichier est sélectionné, mettez à jour l'état avec l'image choisie
if (pickedFile != null) {
setState(() {
_selectedImageFile = File(pickedFile.path);
widget.onImagePicked(_selectedImageFile); // Passez l'image au parent
// Log : Image sélectionnée
debugPrint('Image sélectionnée : ${_selectedImageFile?.path}');
});
}
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: _pickImage, // Ouvre le modal lors du clic
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Aperçu de l\'image (16:9)',
style: TextStyle(color: Colors.blueGrey),
),
const SizedBox(height: 8),
AnimatedContainer(
duration: const Duration(milliseconds: 300), // Animation douce lors du changement d'image
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.blueGrey.withOpacity(0.1), // Fond légèrement opaque
borderRadius: BorderRadius.circular(12), // Bordures arrondies
border: Border.all(
color: _selectedImageFile != null ? Colors.blue : Colors.blueGrey,
width: 2, // Bordure visible autour de l'image
),
),
child: AspectRatio(
aspectRatio: 16 / 9, // Maintient l'aspect ratio de l'image
child: _selectedImageFile != null
? ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image.file(
_selectedImageFile!,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return const Center(
child: Icon(Icons.error, color: Colors.red),
);
},
),
)
: const Center(
child: Text(
'Cliquez pour ajouter une image',
style: TextStyle(color: Colors.blueGrey),
),
),
),
),
],
),
);
}
}