refactor: Clean up code by removing unnecessary whitespace and improving readability
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -11,10 +11,7 @@ import '../../services/error_service.dart';
|
||||
class AddActivityBottomSheet extends StatefulWidget {
|
||||
final Trip trip;
|
||||
|
||||
const AddActivityBottomSheet({
|
||||
Key? key,
|
||||
required this.trip,
|
||||
}) : super(key: key);
|
||||
const AddActivityBottomSheet({super.key, required this.trip});
|
||||
|
||||
@override
|
||||
State<AddActivityBottomSheet> createState() => _AddActivityBottomSheetState();
|
||||
@@ -26,7 +23,7 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
final _descriptionController = TextEditingController();
|
||||
final _addressController = TextEditingController();
|
||||
final ErrorService _errorService = ErrorService();
|
||||
|
||||
|
||||
ActivityCategory _selectedCategory = ActivityCategory.attraction;
|
||||
bool _isLoading = false;
|
||||
|
||||
@@ -43,16 +40,11 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
final theme = Theme.of(context);
|
||||
final mediaQuery = MediaQuery.of(context);
|
||||
final keyboardHeight = mediaQuery.viewInsets.bottom;
|
||||
|
||||
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
height: mediaQuery.size.height * 0.85,
|
||||
margin: EdgeInsets.only(
|
||||
left: 16,
|
||||
right: 16,
|
||||
top: 16,
|
||||
bottom: 16,
|
||||
),
|
||||
margin: EdgeInsets.only(left: 16, right: 16, top: 16, bottom: 16),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.cardColor,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
@@ -167,7 +159,9 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
onPressed: () => Navigator.pop(context),
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
side: BorderSide(color: theme.colorScheme.outline),
|
||||
side: BorderSide(
|
||||
color: theme.colorScheme.outline,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
@@ -193,7 +187,9 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
Colors.white,
|
||||
),
|
||||
),
|
||||
)
|
||||
: const Text('Ajouter'),
|
||||
@@ -214,9 +210,9 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
style: Theme.of(
|
||||
context,
|
||||
).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w600),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -240,17 +236,17 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: isDarkMode
|
||||
? Colors.white.withOpacity(0.2)
|
||||
: Colors.black.withOpacity(0.2),
|
||||
color: isDarkMode
|
||||
? Colors.white.withOpacity(0.2)
|
||||
: Colors.black.withOpacity(0.2),
|
||||
),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: isDarkMode
|
||||
? Colors.white.withOpacity(0.2)
|
||||
: Colors.black.withOpacity(0.2),
|
||||
color: isDarkMode
|
||||
? Colors.white.withOpacity(0.2)
|
||||
: Colors.black.withOpacity(0.2),
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
@@ -265,15 +261,13 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
|
||||
Widget _buildCategorySelector() {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: theme.colorScheme.outline.withOpacity(0.5),
|
||||
),
|
||||
border: Border.all(color: theme.colorScheme.outline.withOpacity(0.5)),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -290,7 +284,7 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
runSpacing: 8,
|
||||
children: ActivityCategory.values.map((category) {
|
||||
final isSelected = _selectedCategory == category;
|
||||
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
@@ -298,12 +292,17 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 8,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? Colors.blue : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(
|
||||
color: isSelected ? Colors.blue : theme.colorScheme.outline,
|
||||
color: isSelected
|
||||
? Colors.blue
|
||||
: theme.colorScheme.outline,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
@@ -312,17 +311,17 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
Icon(
|
||||
_getCategoryIcon(category),
|
||||
size: 16,
|
||||
color: isSelected
|
||||
? Colors.white
|
||||
: theme.colorScheme.onSurface,
|
||||
color: isSelected
|
||||
? Colors.white
|
||||
: theme.colorScheme.onSurface,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
category.displayName,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: isSelected
|
||||
? Colors.white
|
||||
: theme.colorScheme.onSurface,
|
||||
color: isSelected
|
||||
? Colors.white
|
||||
: theme.colorScheme.onSurface,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
@@ -361,19 +360,18 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
name: _nameController.text.trim(),
|
||||
description: _descriptionController.text.trim(),
|
||||
category: _selectedCategory.displayName,
|
||||
address: _addressController.text.trim().isNotEmpty
|
||||
? _addressController.text.trim()
|
||||
: null,
|
||||
address: _addressController.text.trim().isNotEmpty
|
||||
? _addressController.text.trim()
|
||||
: null,
|
||||
votes: {},
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
);
|
||||
|
||||
context.read<ActivityBloc>().add(AddActivity(activity));
|
||||
|
||||
|
||||
// Fermer le bottom sheet
|
||||
Navigator.pop(context);
|
||||
|
||||
} catch (e) {
|
||||
_errorService.showSnackbar(
|
||||
message: 'Erreur lors de l\'ajout de l\'activité',
|
||||
@@ -412,4 +410,4 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
return Icons.spa;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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