Refactoring + Checkpoint
This commit is contained in:
@@ -2,6 +2,11 @@ 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 {
|
||||
final void Function(File?) onImagePicked;
|
||||
|
||||
@@ -14,9 +19,14 @@ class ImagePreviewPicker extends StatefulWidget {
|
||||
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) {
|
||||
@@ -26,14 +36,14 @@ class _ImagePreviewPickerState extends State<ImagePreviewPicker> {
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.camera_alt),
|
||||
title: const Text('Take a Photo'),
|
||||
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('Choose from Gallery'),
|
||||
title: const Text('Choisir depuis la galerie'),
|
||||
onTap: () async {
|
||||
Navigator.pop(context, await picker.pickImage(source: ImageSource.gallery));
|
||||
},
|
||||
@@ -44,10 +54,13 @@ class _ImagePreviewPickerState extends State<ImagePreviewPicker> {
|
||||
},
|
||||
);
|
||||
|
||||
// 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); // Pass the picked image to the parent
|
||||
widget.onImagePicked(_selectedImageFile); // Passez l'image au parent
|
||||
// Log : Image sélectionnée
|
||||
debugPrint('Image sélectionnée : ${_selectedImageFile?.path}');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -55,23 +68,28 @@ class _ImagePreviewPickerState extends State<ImagePreviewPicker> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: _pickImage,
|
||||
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.white70),
|
||||
style: TextStyle(color: Colors.blueGrey),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
AspectRatio(
|
||||
aspectRatio: 16 / 9,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black26,
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
border: Border.all(color: Colors.white70, width: 1),
|
||||
AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300), // Animation douce lors du changement d'image
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blueGrey.withOpacity(0.1), // Fond légèrement opaque
|
||||
borderRadius: BorderRadius.circular(12.0), // Bordures arrondies
|
||||
border: Border.all(
|
||||
color: _selectedImageFile != null ? Colors.blue : Colors.blueGrey,
|
||||
width: 2.0, // 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.0),
|
||||
@@ -88,7 +106,7 @@ class _ImagePreviewPickerState extends State<ImagePreviewPicker> {
|
||||
: const Center(
|
||||
child: Text(
|
||||
'Cliquez pour ajouter une image',
|
||||
style: TextStyle(color: Colors.white54),
|
||||
style: TextStyle(color: Colors.blueGrey),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user