feat: Add TripImageService for automatic trip image management
- Implemented TripImageService to load missing images for trips, reload images, and clean up unused images. - Added functionality to get image statistics and clean up duplicate images. - Created utility scripts for manual image cleanup and diagnostics in Firebase Storage. - Introduced tests for image loading optimization and photo quality algorithms. - Updated dependencies in pubspec.yaml and pubspec.lock for image handling.
This commit is contained in:
@@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:travel_mate/components/home/create_trip_content.dart';
|
||||
import '../home/show_trip_details_content.dart';
|
||||
import 'package:travel_mate/components/home/trip_card.dart';
|
||||
import 'package:travel_mate/services/trip_image_service.dart';
|
||||
import '../../blocs/user/user_bloc.dart';
|
||||
import '../../blocs/user/user_state.dart';
|
||||
import '../../blocs/trip/trip_bloc.dart';
|
||||
@@ -38,6 +40,9 @@ class _HomeContentState extends State<HomeContent>
|
||||
/// Flag to prevent duplicate trip loading operations
|
||||
bool _hasLoadedTrips = false;
|
||||
|
||||
/// Service pour charger les images manquantes
|
||||
final TripImageService _tripImageService = TripImageService();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -274,197 +279,41 @@ class _HomeContentState extends State<HomeContent>
|
||||
}
|
||||
|
||||
Widget _buildTripsList(List<Trip> trips) {
|
||||
return Column(children: trips.map((trip) => _buildTripCard(trip)).toList());
|
||||
}
|
||||
|
||||
Widget _buildTripCard(Trip trip) {
|
||||
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
||||
final textColor = isDarkMode ? Colors.white : Colors.black;
|
||||
final subtextColor = isDarkMode ? Colors.white70 : Colors.grey[600];
|
||||
|
||||
return Card(
|
||||
margin: EdgeInsets.only(bottom: 12),
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Image en haut de la carte
|
||||
Container(
|
||||
height: 200,
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(12),
|
||||
topRight: Radius.circular(12),
|
||||
),
|
||||
color: Colors.grey[300],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: Radius.circular(12),
|
||||
topRight: Radius.circular(12),
|
||||
),
|
||||
child: trip.imageUrl != null && trip.imageUrl!.isNotEmpty
|
||||
? Image.network(
|
||||
trip.imageUrl!,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return Container(
|
||||
color: Colors.grey[300],
|
||||
child: Icon(
|
||||
Icons.image_not_supported,
|
||||
size: 50,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
: Container(
|
||||
color: Colors.grey[300],
|
||||
child: Icon(
|
||||
Icons.travel_explore,
|
||||
size: 50,
|
||||
color: Colors.grey[600],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Contenu de la carte
|
||||
Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Nom du voyage
|
||||
Text(
|
||||
trip.title,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: textColor,
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 8),
|
||||
|
||||
// Section dates, participants et bouton
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Colonne gauche : dates et participants
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Dates
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.calendar_today,
|
||||
size: 16,
|
||||
color: subtextColor,
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
Text(
|
||||
'${_formatDate(trip.startDate)} - ${_formatDate(trip.endDate)}',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: subtextColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
SizedBox(height: 8),
|
||||
|
||||
// Nombre de participants
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.people, size: 16, color: subtextColor),
|
||||
SizedBox(width: 4),
|
||||
Text(
|
||||
'${trip.participants.length} participant${trip.participants.length > 1 ? 's' : ''}',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: subtextColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Bouton "Voir" à droite
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
final result = await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
ShowTripDetailsContent(trip: trip),
|
||||
),
|
||||
);
|
||||
|
||||
if (result == true && mounted) {
|
||||
final userState = context.read<UserBloc>().state;
|
||||
if (userState is UserLoaded) {
|
||||
context.read<TripBloc>().add(
|
||||
LoadTripsByUserId(userId: userState.user.id),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
foregroundColor: Theme.of(
|
||||
context,
|
||||
).colorScheme.onPrimary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 8,
|
||||
),
|
||||
),
|
||||
child: Text('Voir', style: TextStyle(fontSize: 14)),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
// Charger les images manquantes en arrière-plan
|
||||
_loadMissingImagesInBackground(trips);
|
||||
|
||||
return Column(
|
||||
children: trips.map((trip) => TripCard(
|
||||
trip: trip,
|
||||
onTap: () => _showTripDetails(trip),
|
||||
)).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
// Color _getStatusColor(Trip trip) {
|
||||
// final now = DateTime.now();
|
||||
// if (now.isBefore(trip.startDate)) {
|
||||
// return Colors.blue;
|
||||
// } else if (now.isAfter(trip.endDate)) {
|
||||
// return Colors.grey;
|
||||
// } else {
|
||||
// return Colors.green;
|
||||
// }
|
||||
// }
|
||||
/// Charge les images manquantes en arrière-plan
|
||||
void _loadMissingImagesInBackground(List<Trip> trips) {
|
||||
// Lancer le chargement des images en arrière-plan sans bloquer l'UI
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_tripImageService.loadMissingImages(trips);
|
||||
});
|
||||
}
|
||||
|
||||
// String _getStatusText(Trip trip) {
|
||||
// final now = DateTime.now();
|
||||
// if (now.isBefore(trip.startDate)) {
|
||||
// return 'À venir';
|
||||
// } else if (now.isAfter(trip.endDate)) {
|
||||
// return 'Terminé';
|
||||
// } else {
|
||||
// return 'En cours';
|
||||
// }
|
||||
// }
|
||||
/// Navigate to trip details page
|
||||
Future<void> _showTripDetails(Trip trip) async {
|
||||
final result = await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ShowTripDetailsContent(trip: trip),
|
||||
),
|
||||
);
|
||||
|
||||
String _formatDate(DateTime date) {
|
||||
return '${date.day.toString().padLeft(2, '0')}/${date.month.toString().padLeft(2, '0')}/${date.year}';
|
||||
if (result == true && mounted) {
|
||||
final userState = context.read<UserBloc>().state;
|
||||
if (userState is UserLoaded) {
|
||||
context.read<TripBloc>().add(
|
||||
LoadTripsByUserId(userId: userState.user.id),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user