refactor: Clean up code by removing unnecessary whitespace and improving readability
This commit is contained in:
@@ -8,11 +8,7 @@ class TripCard extends StatefulWidget {
|
||||
final Trip trip;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const TripCard({
|
||||
super.key,
|
||||
required this.trip,
|
||||
this.onTap,
|
||||
});
|
||||
const TripCard({super.key, required this.trip, this.onTap});
|
||||
|
||||
@override
|
||||
State<TripCard> createState() => _TripCardState();
|
||||
@@ -29,7 +25,7 @@ class _TripCardState extends State<TripCard> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
_currentImageUrl = widget.trip.imageUrl;
|
||||
|
||||
|
||||
// Si aucune image n'est disponible, essayer de la charger
|
||||
if (_currentImageUrl == null || _currentImageUrl!.isEmpty) {
|
||||
_loadImageForTrip();
|
||||
@@ -38,28 +34,29 @@ class _TripCardState extends State<TripCard> {
|
||||
|
||||
Future<void> _loadImageForTrip() async {
|
||||
if (_hasTriedLoading || _isLoadingImage) return;
|
||||
|
||||
|
||||
setState(() {
|
||||
_isLoadingImage = true;
|
||||
_hasTriedLoading = true;
|
||||
});
|
||||
|
||||
try {
|
||||
|
||||
// D'abord vérifier si une image existe déjà dans le Storage
|
||||
String? imageUrl = await _placeImageService.getExistingImageUrl(widget.trip.location);
|
||||
|
||||
String? imageUrl = await _placeImageService.getExistingImageUrl(
|
||||
widget.trip.location,
|
||||
);
|
||||
|
||||
// Si aucune image n'existe, en télécharger une nouvelle
|
||||
if (imageUrl == null) {
|
||||
imageUrl = await _placeImageService.getPlaceImageUrl(widget.trip.location);
|
||||
}
|
||||
|
||||
imageUrl ??= await _placeImageService.getPlaceImageUrl(
|
||||
widget.trip.location,
|
||||
);
|
||||
|
||||
if (mounted && imageUrl != null) {
|
||||
setState(() {
|
||||
_currentImageUrl = imageUrl;
|
||||
_isLoadingImage = false;
|
||||
});
|
||||
|
||||
|
||||
// Mettre à jour le voyage dans la base de données avec l'imageUrl
|
||||
_updateTripWithImage(imageUrl);
|
||||
} else {
|
||||
@@ -84,7 +81,7 @@ class _TripCardState extends State<TripCard> {
|
||||
imageUrl: imageUrl,
|
||||
updatedAt: DateTime.now(),
|
||||
);
|
||||
|
||||
|
||||
// Mettre à jour dans la base de données
|
||||
await _tripRepository.updateTrip(widget.trip.id!, updatedTrip);
|
||||
}
|
||||
@@ -95,7 +92,7 @@ class _TripCardState extends State<TripCard> {
|
||||
|
||||
Widget _buildImageWidget() {
|
||||
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
|
||||
if (_isLoadingImage) {
|
||||
return Container(
|
||||
color: isDarkMode ? Colors.grey[700] : Colors.grey[200],
|
||||
@@ -111,21 +108,20 @@ class _TripCardState extends State<TripCard> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (_currentImageUrl != null && _currentImageUrl!.isNotEmpty) {
|
||||
return CachedNetworkImage(
|
||||
imageUrl: _currentImageUrl!,
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (context, url) => Container(
|
||||
color: Colors.grey[200],
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
child: const Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
errorWidget: (context, url, error) => _buildPlaceholderImage(isDarkMode),
|
||||
errorWidget: (context, url, error) =>
|
||||
_buildPlaceholderImage(isDarkMode),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return _buildPlaceholderImage(isDarkMode);
|
||||
}
|
||||
|
||||
@@ -140,9 +136,7 @@ class _TripCardState extends State<TripCard> {
|
||||
elevation: 4,
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
color: cardColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
@@ -153,7 +147,9 @@ class _TripCardState extends State<TripCard> {
|
||||
children: [
|
||||
// Image du voyage
|
||||
ClipRRect(
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(12)),
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12),
|
||||
),
|
||||
child: SizedBox(
|
||||
height: 200,
|
||||
width: double.infinity,
|
||||
@@ -178,7 +174,7 @@ class _TripCardState extends State<TripCard> {
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
|
||||
// Dates, participants et bouton voir
|
||||
Row(
|
||||
children: [
|
||||
@@ -207,14 +203,17 @@ class _TripCardState extends State<TripCard> {
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
// Bouton Voir
|
||||
ElevatedButton(
|
||||
onPressed: widget.onTap,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.blue,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 20,
|
||||
vertical: 8,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
@@ -229,8 +228,8 @@ class _TripCardState extends State<TripCard> {
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -261,4 +260,4 @@ class _TripCardState extends State<TripCard> {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user