refactor: Clean up code by removing unnecessary whitespace and improving readability
This commit is contained in:
@@ -10,10 +10,7 @@ import '../activities/add_activity_bottom_sheet.dart';
|
||||
class ActivitiesPage extends StatefulWidget {
|
||||
final Trip trip;
|
||||
|
||||
const ActivitiesPage({
|
||||
super.key,
|
||||
required this.trip,
|
||||
});
|
||||
const ActivitiesPage({super.key, required this.trip});
|
||||
|
||||
@override
|
||||
State<ActivitiesPage> createState() => _ActivitiesPageState();
|
||||
@@ -35,9 +32,12 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
List<Activity> _tripActivities = [];
|
||||
List<Activity> _approvedActivities = [];
|
||||
bool _isLoadingTripActivities = false;
|
||||
int _totalGoogleActivitiesRequested = 0; // Compteur pour les recherches progressives
|
||||
bool _autoReloadInProgress = false; // Protection contre les rechargements en boucle
|
||||
int _lastAutoReloadTriggerCount = 0; // Éviter de redéclencher pour le même nombre
|
||||
int _totalGoogleActivitiesRequested =
|
||||
0; // Compteur pour les recherches progressives
|
||||
bool _autoReloadInProgress =
|
||||
false; // Protection contre les rechargements en boucle
|
||||
int _lastAutoReloadTriggerCount =
|
||||
0; // Éviter de redéclencher pour le même nombre
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true; // Maintient l'état de la page
|
||||
@@ -131,14 +131,20 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
setState(() {
|
||||
_tripActivities = state.activities;
|
||||
_approvedActivities = state.activities.where((a) => a.totalVotes > 0).toList();
|
||||
_approvedActivities = state.activities
|
||||
.where((a) => a.totalVotes > 0)
|
||||
.toList();
|
||||
_isLoadingTripActivities = false;
|
||||
});
|
||||
|
||||
print('🔄 [ActivityLoaded] Activités du voyage mises à jour: ${_tripActivities.length}');
|
||||
print(
|
||||
'🔄 [ActivityLoaded] Activités du voyage mises à jour: ${_tripActivities.length}',
|
||||
);
|
||||
// Vérifier si on a besoin de charger plus d'activités dans les suggestions
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
print('🚀 [ActivityLoaded] Déclenchement de la vérification auto-reload');
|
||||
print(
|
||||
'🚀 [ActivityLoaded] Déclenchement de la vérification auto-reload',
|
||||
);
|
||||
_checkAndLoadMoreActivitiesIfNeeded();
|
||||
});
|
||||
});
|
||||
@@ -150,7 +156,9 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
// et pas pour les rechargements automatiques
|
||||
if (state.searchResults.length <= 6 && !_autoReloadInProgress) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
print('🎯 [ActivitySearchResults] Première recherche avec peu de résultats, vérification auto-reload');
|
||||
print(
|
||||
'🎯 [ActivitySearchResults] Première recherche avec peu de résultats, vérification auto-reload',
|
||||
);
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
_checkAndLoadMoreActivitiesIfNeeded();
|
||||
});
|
||||
@@ -296,9 +304,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: theme.colorScheme.outline.withOpacity(0.5),
|
||||
),
|
||||
border: Border.all(color: theme.colorScheme.outline.withOpacity(0.5)),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: theme.colorScheme.surface,
|
||||
),
|
||||
@@ -383,7 +389,8 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
constraints: BoxConstraints(
|
||||
maxHeight: MediaQuery.of(context).size.height * 0.7, // Limite à 70% de l'écran
|
||||
maxHeight:
|
||||
MediaQuery.of(context).size.height * 0.7, // Limite à 70% de l'écran
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -399,19 +406,26 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
Flexible(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: categories.map((category) => ListTile(
|
||||
title: Text(category),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_selectedCategory = category;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
_applyFilters();
|
||||
},
|
||||
trailing: _selectedCategory == category
|
||||
? Icon(Icons.check, color: theme.colorScheme.primary)
|
||||
: null,
|
||||
)).toList(),
|
||||
children: categories
|
||||
.map(
|
||||
(category) => ListTile(
|
||||
title: Text(category),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_selectedCategory = category;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
_applyFilters();
|
||||
},
|
||||
trailing: _selectedCategory == category
|
||||
? Icon(
|
||||
Icons.check,
|
||||
color: theme.colorScheme.primary,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -422,7 +436,14 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
|
||||
Widget _buildPriceFilterSheet() {
|
||||
final theme = Theme.of(context);
|
||||
final prices = ['Prix', 'Gratuit', 'Bon marché', 'Modéré', 'Cher', 'Très cher'];
|
||||
final prices = [
|
||||
'Prix',
|
||||
'Gratuit',
|
||||
'Bon marché',
|
||||
'Modéré',
|
||||
'Cher',
|
||||
'Très cher',
|
||||
];
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
@@ -443,19 +464,26 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
Flexible(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: prices.map((price) => ListTile(
|
||||
title: Text(price),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_selectedPrice = price;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
_applyFilters();
|
||||
},
|
||||
trailing: _selectedPrice == price
|
||||
? Icon(Icons.check, color: theme.colorScheme.primary)
|
||||
: null,
|
||||
)).toList(),
|
||||
children: prices
|
||||
.map(
|
||||
(price) => ListTile(
|
||||
title: Text(price),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_selectedPrice = price;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
_applyFilters();
|
||||
},
|
||||
trailing: _selectedPrice == price
|
||||
? Icon(
|
||||
Icons.check,
|
||||
color: theme.colorScheme.primary,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -466,7 +494,13 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
|
||||
Widget _buildRatingFilterSheet() {
|
||||
final theme = Theme.of(context);
|
||||
final ratings = ['Note', '4+ étoiles', '3+ étoiles', '2+ étoiles', '1+ étoiles'];
|
||||
final ratings = [
|
||||
'Note',
|
||||
'4+ étoiles',
|
||||
'3+ étoiles',
|
||||
'2+ étoiles',
|
||||
'1+ étoiles',
|
||||
];
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
@@ -487,19 +521,26 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
Flexible(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: ratings.map((rating) => ListTile(
|
||||
title: Text(rating),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_selectedRating = rating;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
_applyFilters();
|
||||
},
|
||||
trailing: _selectedRating == rating
|
||||
? Icon(Icons.check, color: theme.colorScheme.primary)
|
||||
: null,
|
||||
)).toList(),
|
||||
children: ratings
|
||||
.map(
|
||||
(rating) => ListTile(
|
||||
title: Text(rating),
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_selectedRating = rating;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
_applyFilters();
|
||||
},
|
||||
trailing: _selectedRating == rating
|
||||
? Icon(
|
||||
Icons.check,
|
||||
color: theme.colorScheme.primary,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -509,13 +550,14 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
}
|
||||
|
||||
void _applyFilters() {
|
||||
String? category = _selectedCategory == 'Toutes les catégories' ? null : _selectedCategory;
|
||||
String? category = _selectedCategory == 'Toutes les catégories'
|
||||
? null
|
||||
: _selectedCategory;
|
||||
double? minRating = _getMinRatingFromString(_selectedRating);
|
||||
|
||||
context.read<ActivityBloc>().add(FilterActivities(
|
||||
category: category,
|
||||
minRating: minRating,
|
||||
));
|
||||
context.read<ActivityBloc>().add(
|
||||
FilterActivities(category: category, minRating: minRating),
|
||||
);
|
||||
}
|
||||
|
||||
double? _getMinRatingFromString(String rating) {
|
||||
@@ -605,11 +647,16 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
|
||||
// Filtrer les activités déjà présentes dans le voyage
|
||||
final filteredActivities = googleActivities.where((googleActivity) {
|
||||
return !_tripActivities.any((tripActivity) =>
|
||||
tripActivity.name.toLowerCase().trim() == googleActivity.name.toLowerCase().trim());
|
||||
return !_tripActivities.any(
|
||||
(tripActivity) =>
|
||||
tripActivity.name.toLowerCase().trim() ==
|
||||
googleActivity.name.toLowerCase().trim(),
|
||||
);
|
||||
}).toList();
|
||||
|
||||
print('🔍 [Google Search] ${googleActivities.length} résultats trouvés, ${filteredActivities.length} après filtrage');
|
||||
print(
|
||||
'🔍 [Google Search] ${googleActivities.length} résultats trouvés, ${filteredActivities.length} après filtrage',
|
||||
);
|
||||
|
||||
if (filteredActivities.isEmpty && googleActivities.isNotEmpty) {
|
||||
return Column(
|
||||
@@ -626,7 +673,10 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
icon: const Icon(Icons.add_circle_outline),
|
||||
label: const Text('Rechercher plus d\'activités'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -648,7 +698,10 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: const Text('Rechercher à nouveau'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 12),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -668,7 +721,10 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
itemCount: filteredActivities.length,
|
||||
itemBuilder: (context, index) {
|
||||
final activity = filteredActivities[index];
|
||||
return _buildActivityCard(activity, isGoogleSuggestion: true);
|
||||
return _buildActivityCard(
|
||||
activity,
|
||||
isGoogleSuggestion: true,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -678,9 +734,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
if (state.isLoading)
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
child: const Center(child: CircularProgressIndicator()),
|
||||
)
|
||||
else
|
||||
Column(
|
||||
@@ -694,7 +748,9 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
label: const Text('Rechercher plus d\'activités'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
backgroundColor: Theme.of(
|
||||
context,
|
||||
).colorScheme.primary,
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
@@ -708,10 +764,18 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () {
|
||||
print('🧪 [DEBUG] Force auto-reload check - État actuel:');
|
||||
print('🧪 [DEBUG] _tripActivities: ${_tripActivities.length}');
|
||||
print('🧪 [DEBUG] _autoReloadInProgress: $_autoReloadInProgress');
|
||||
print('🧪 [DEBUG] _lastAutoReloadTriggerCount: $_lastAutoReloadTriggerCount');
|
||||
print(
|
||||
'🧪 [DEBUG] Force auto-reload check - État actuel:',
|
||||
);
|
||||
print(
|
||||
'🧪 [DEBUG] _tripActivities: ${_tripActivities.length}',
|
||||
);
|
||||
print(
|
||||
'🧪 [DEBUG] _autoReloadInProgress: $_autoReloadInProgress',
|
||||
);
|
||||
print(
|
||||
'🧪 [DEBUG] _lastAutoReloadTriggerCount: $_lastAutoReloadTriggerCount',
|
||||
);
|
||||
_checkAndLoadMoreActivitiesIfNeeded();
|
||||
},
|
||||
icon: const Icon(Icons.bug_report, size: 16),
|
||||
@@ -742,7 +806,10 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
icon: const Icon(Icons.search),
|
||||
label: const Text('Rechercher des activités (6 résultats)'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 16),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 32,
|
||||
vertical: 16,
|
||||
),
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
@@ -768,11 +835,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
size: 64,
|
||||
color: theme.colorScheme.outline,
|
||||
),
|
||||
Icon(icon, size: 64, color: theme.colorScheme.outline),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
title,
|
||||
@@ -809,36 +872,43 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
}
|
||||
},
|
||||
child: activities.isEmpty
|
||||
? ListView(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: MediaQuery.of(context).size.height * 0.6,
|
||||
child: _buildEmptyState(
|
||||
'Aucune activité',
|
||||
'Tirez vers le bas pour actualiser',
|
||||
Icons.refresh,
|
||||
? ListView(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: MediaQuery.of(context).size.height * 0.6,
|
||||
child: _buildEmptyState(
|
||||
'Aucune activité',
|
||||
'Tirez vers le bas pour actualiser',
|
||||
Icons.refresh,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: activities.length,
|
||||
itemBuilder: (context, index) {
|
||||
final activity = activities[index];
|
||||
return _buildActivityCard(activity);
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
itemCount: activities.length,
|
||||
itemBuilder: (context, index) {
|
||||
final activity = activities[index];
|
||||
return _buildActivityCard(activity);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildActivityCard(Activity activity, {bool isGoogleSuggestion = false}) {
|
||||
Widget _buildActivityCard(
|
||||
Activity activity, {
|
||||
bool isGoogleSuggestion = false,
|
||||
}) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
// Vérifier si l'activité existe déjà dans le voyage (pour les suggestions Google)
|
||||
final bool activityAlreadyExists = isGoogleSuggestion &&
|
||||
_tripActivities.any((tripActivity) =>
|
||||
tripActivity.name.toLowerCase().trim() == activity.name.toLowerCase().trim());
|
||||
final bool activityAlreadyExists =
|
||||
isGoogleSuggestion &&
|
||||
_tripActivities.any(
|
||||
(tripActivity) =>
|
||||
tripActivity.name.toLowerCase().trim() ==
|
||||
activity.name.toLowerCase().trim(),
|
||||
);
|
||||
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
@@ -848,8 +918,10 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
// Image de l'activité
|
||||
if (activity.imageUrl != null && activity.imageUrl!.isNotEmpty)
|
||||
ClipRRect(
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(12)),
|
||||
child: Container(
|
||||
borderRadius: const BorderRadius.vertical(
|
||||
top: Radius.circular(12),
|
||||
),
|
||||
child: SizedBox(
|
||||
height: 200,
|
||||
width: double.infinity,
|
||||
child: Image.network(
|
||||
@@ -887,7 +959,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
child: CircularProgressIndicator(
|
||||
value: loadingProgress.expectedTotalBytes != null
|
||||
? loadingProgress.cumulativeBytesLoaded /
|
||||
loadingProgress.expectedTotalBytes!
|
||||
loadingProgress.expectedTotalBytes!
|
||||
: null,
|
||||
),
|
||||
),
|
||||
@@ -942,7 +1014,10 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
// Note
|
||||
if (activity.rating != null)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.amber.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
@@ -950,7 +1025,11 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.star, color: Colors.amber, size: 16),
|
||||
const Icon(
|
||||
Icons.star,
|
||||
color: Colors.amber,
|
||||
size: 16,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
activity.rating!.toStringAsFixed(1),
|
||||
@@ -1004,11 +1083,16 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
if (activityAlreadyExists) ...[
|
||||
// Activité déjà dans le voyage
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 8,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orange.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: Colors.orange.withOpacity(0.3)),
|
||||
border: Border.all(
|
||||
color: Colors.orange.withOpacity(0.3),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -1055,7 +1139,10 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
children: [
|
||||
// Votes positifs (pouces verts)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.green.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
@@ -1082,7 +1169,10 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
const SizedBox(width: 8),
|
||||
// Votes négatifs (pouces rouges)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8,
|
||||
vertical: 4,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
@@ -1167,14 +1257,14 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
// Pour l'instant, on utilise un ID temporaire
|
||||
final userId = 'current_user_id';
|
||||
|
||||
context.read<ActivityBloc>().add(VoteForActivity(
|
||||
activityId: activityId,
|
||||
userId: userId,
|
||||
vote: vote,
|
||||
));
|
||||
context.read<ActivityBloc>().add(
|
||||
VoteForActivity(activityId: activityId, userId: userId, vote: vote),
|
||||
);
|
||||
|
||||
// Afficher un feedback à l'utilisateur
|
||||
final message = vote == 1 ? 'Vote positif ajouté !' : 'Vote négatif ajouté !';
|
||||
final message = vote == 1
|
||||
? 'Vote positif ajouté !'
|
||||
: 'Vote négatif ajouté !';
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
@@ -1225,24 +1315,35 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
if (currentState is ActivitySearchResults) {
|
||||
final googleActivities = currentState.searchResults;
|
||||
|
||||
print('🔍 [Auto-reload] Activités du voyage en mémoire: ${_tripActivities.length}');
|
||||
print('🔍 [Auto-reload] Activités Google total: ${googleActivities.length}');
|
||||
print(
|
||||
'🔍 [Auto-reload] Activités du voyage en mémoire: ${_tripActivities.length}',
|
||||
);
|
||||
print(
|
||||
'🔍 [Auto-reload] Activités Google total: ${googleActivities.length}',
|
||||
);
|
||||
|
||||
// Filtrer les activités déjà présentes dans le voyage
|
||||
final filteredActivities = googleActivities.where((googleActivity) {
|
||||
final isDuplicate = _tripActivities.any((tripActivity) =>
|
||||
tripActivity.name.toLowerCase().trim() == googleActivity.name.toLowerCase().trim());
|
||||
final isDuplicate = _tripActivities.any(
|
||||
(tripActivity) =>
|
||||
tripActivity.name.toLowerCase().trim() ==
|
||||
googleActivity.name.toLowerCase().trim(),
|
||||
);
|
||||
if (isDuplicate) {
|
||||
print('🔍 [Auto-reload] Activité filtrée: ${googleActivity.name}');
|
||||
}
|
||||
return !isDuplicate;
|
||||
}).toList();
|
||||
|
||||
print('🔍 [Auto-reload] ${filteredActivities.length} activités visibles après filtrage sur ${googleActivities.length} total');
|
||||
print(
|
||||
'🔍 [Auto-reload] ${filteredActivities.length} activités visibles après filtrage sur ${googleActivities.length} total',
|
||||
);
|
||||
|
||||
// Protection: ne pas redéclencher pour le même nombre d'activités Google
|
||||
if (googleActivities.length == _lastAutoReloadTriggerCount) {
|
||||
print('🔒 [Auto-reload] Même nombre qu\'avant (${googleActivities.length}), skip pour éviter la boucle');
|
||||
print(
|
||||
'🔒 [Auto-reload] Même nombre qu\'avant (${googleActivities.length}), skip pour éviter la boucle',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1252,11 +1353,19 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
_lastAutoReloadTriggerCount = googleActivities.length;
|
||||
|
||||
// Calculer combien d'activités on doit demander
|
||||
final activitiesNeeded = 6 - filteredActivities.length; // Manque pour arriver à 6
|
||||
final newTotalToRequest = googleActivities.length + activitiesNeeded + 6; // Activités actuelles + ce qui manque + buffer de 6
|
||||
final activitiesNeeded =
|
||||
6 - filteredActivities.length; // Manque pour arriver à 6
|
||||
final newTotalToRequest =
|
||||
googleActivities.length +
|
||||
activitiesNeeded +
|
||||
6; // Activités actuelles + ce qui manque + buffer de 6
|
||||
|
||||
print('🔄 [Auto-reload] DÉCLENCHEMENT: Besoin de ${activitiesNeeded} activités supplémentaires');
|
||||
print('📊 [Auto-reload] Demande totale: ${newTotalToRequest} activités (actuellement: ${googleActivities.length})');
|
||||
print(
|
||||
'🔄 [Auto-reload] DÉCLENCHEMENT: Besoin de $activitiesNeeded activités supplémentaires',
|
||||
);
|
||||
print(
|
||||
'📊 [Auto-reload] Demande totale: $newTotalToRequest activités (actuellement: ${googleActivities.length})',
|
||||
);
|
||||
|
||||
// Mettre à jour le compteur et recharger avec le nouveau total
|
||||
_totalGoogleActivitiesRequested = newTotalToRequest;
|
||||
@@ -1268,12 +1377,18 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
print('🔓 [Auto-reload] Verrou libéré');
|
||||
});
|
||||
} else if (filteredActivities.length >= 4) {
|
||||
print('✅ [Auto-reload] Suffisamment d\'activités visibles (${filteredActivities.length} >= 4)');
|
||||
print(
|
||||
'✅ [Auto-reload] Suffisamment d\'activités visibles (${filteredActivities.length} >= 4)',
|
||||
);
|
||||
} else {
|
||||
print('🚫 [Auto-reload] Trop d\'activités Google déjà chargées (${googleActivities.length} >= 20), arrêt auto-reload');
|
||||
print(
|
||||
'🚫 [Auto-reload] Trop d\'activités Google déjà chargées (${googleActivities.length} >= 20), arrêt auto-reload',
|
||||
);
|
||||
}
|
||||
} else {
|
||||
print('⚠️ [Auto-reload] État pas prêt pour auto-chargement: ${currentState.runtimeType}');
|
||||
print(
|
||||
'⚠️ [Auto-reload] État pas prêt pour auto-chargement: ${currentState.runtimeType}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1285,24 +1400,32 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
|
||||
// Utiliser les coordonnées pré-géolocalisées du voyage si disponibles
|
||||
if (widget.trip.hasCoordinates) {
|
||||
print('🌍 [Google Search] Using pre-geocoded coordinates: ${widget.trip.latitude}, ${widget.trip.longitude}');
|
||||
context.read<ActivityBloc>().add(SearchActivitiesWithCoordinates(
|
||||
tripId: widget.trip.id!,
|
||||
latitude: widget.trip.latitude!,
|
||||
longitude: widget.trip.longitude!,
|
||||
category: null, // Rechercher dans toutes les catégories
|
||||
maxResults: 6, // Charger 6 résultats à la fois
|
||||
reset: true, // Nouveau flag pour reset
|
||||
));
|
||||
print(
|
||||
'🌍 [Google Search] Using pre-geocoded coordinates: ${widget.trip.latitude}, ${widget.trip.longitude}',
|
||||
);
|
||||
context.read<ActivityBloc>().add(
|
||||
SearchActivitiesWithCoordinates(
|
||||
tripId: widget.trip.id!,
|
||||
latitude: widget.trip.latitude!,
|
||||
longitude: widget.trip.longitude!,
|
||||
category: null, // Rechercher dans toutes les catégories
|
||||
maxResults: 6, // Charger 6 résultats à la fois
|
||||
reset: true, // Nouveau flag pour reset
|
||||
),
|
||||
);
|
||||
} else {
|
||||
print('⚠️ [Google Search] No coordinates available, falling back to destination geocoding');
|
||||
context.read<ActivityBloc>().add(SearchActivities(
|
||||
tripId: widget.trip.id!,
|
||||
destination: widget.trip.location,
|
||||
category: null, // Rechercher dans toutes les catégories
|
||||
maxResults: 6, // Charger 6 résultats à la fois
|
||||
reset: true, // Nouveau flag pour reset
|
||||
));
|
||||
print(
|
||||
'⚠️ [Google Search] No coordinates available, falling back to destination geocoding',
|
||||
);
|
||||
context.read<ActivityBloc>().add(
|
||||
SearchActivities(
|
||||
tripId: widget.trip.id!,
|
||||
destination: widget.trip.location,
|
||||
category: null, // Rechercher dans toutes les catégories
|
||||
maxResults: 6, // Charger 6 résultats à la fois
|
||||
reset: true, // Nouveau flag pour reset
|
||||
),
|
||||
);
|
||||
}
|
||||
_googleSearchPerformed = true;
|
||||
}
|
||||
@@ -1315,24 +1438,32 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
|
||||
// Utiliser les coordonnées pré-géolocalisées du voyage si disponibles
|
||||
if (widget.trip.hasCoordinates) {
|
||||
print('🌍 [Google Search] Using pre-geocoded coordinates: ${widget.trip.latitude}, ${widget.trip.longitude}');
|
||||
context.read<ActivityBloc>().add(SearchActivitiesWithCoordinates(
|
||||
tripId: widget.trip.id!,
|
||||
latitude: widget.trip.latitude!,
|
||||
longitude: widget.trip.longitude!,
|
||||
category: null,
|
||||
maxResults: 6,
|
||||
reset: true,
|
||||
));
|
||||
print(
|
||||
'🌍 [Google Search] Using pre-geocoded coordinates: ${widget.trip.latitude}, ${widget.trip.longitude}',
|
||||
);
|
||||
context.read<ActivityBloc>().add(
|
||||
SearchActivitiesWithCoordinates(
|
||||
tripId: widget.trip.id!,
|
||||
latitude: widget.trip.latitude!,
|
||||
longitude: widget.trip.longitude!,
|
||||
category: null,
|
||||
maxResults: 6,
|
||||
reset: true,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
print('⚠️ [Google Search] No coordinates available, falling back to destination geocoding');
|
||||
context.read<ActivityBloc>().add(SearchActivities(
|
||||
tripId: widget.trip.id!,
|
||||
destination: widget.trip.location,
|
||||
category: null,
|
||||
maxResults: 6,
|
||||
reset: true,
|
||||
));
|
||||
print(
|
||||
'⚠️ [Google Search] No coordinates available, falling back to destination geocoding',
|
||||
);
|
||||
context.read<ActivityBloc>().add(
|
||||
SearchActivities(
|
||||
tripId: widget.trip.id!,
|
||||
destination: widget.trip.location,
|
||||
category: null,
|
||||
maxResults: 6,
|
||||
reset: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
_googleSearchPerformed = true;
|
||||
}
|
||||
@@ -1344,36 +1475,48 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
if (currentState is ActivitySearchResults) {
|
||||
final currentCount = currentState.searchResults.length;
|
||||
final newTotal = currentCount + 6;
|
||||
print('📊 [Google Search] Current results count: $currentCount, requesting total: $newTotal');
|
||||
print(
|
||||
'📊 [Google Search] Current results count: $currentCount, requesting total: $newTotal',
|
||||
);
|
||||
|
||||
_totalGoogleActivitiesRequested = newTotal;
|
||||
|
||||
// Utiliser les coordonnées pré-géolocalisées du voyage si disponibles
|
||||
if (widget.trip.hasCoordinates) {
|
||||
print('🌍 [Google Search] Using pre-geocoded coordinates for more results');
|
||||
context.read<ActivityBloc>().add(SearchActivitiesWithCoordinates(
|
||||
tripId: widget.trip.id!,
|
||||
latitude: widget.trip.latitude!,
|
||||
longitude: widget.trip.longitude!,
|
||||
category: null,
|
||||
maxResults: newTotal, // Demander le total cumulé
|
||||
reset: true, // Reset pour avoir tous les résultats d'un coup
|
||||
));
|
||||
print(
|
||||
'🌍 [Google Search] Using pre-geocoded coordinates for more results',
|
||||
);
|
||||
context.read<ActivityBloc>().add(
|
||||
SearchActivitiesWithCoordinates(
|
||||
tripId: widget.trip.id!,
|
||||
latitude: widget.trip.latitude!,
|
||||
longitude: widget.trip.longitude!,
|
||||
category: null,
|
||||
maxResults: newTotal, // Demander le total cumulé
|
||||
reset: true, // Reset pour avoir tous les résultats d'un coup
|
||||
),
|
||||
);
|
||||
} else {
|
||||
print('⚠️ [Google Search] No coordinates available, falling back to destination geocoding');
|
||||
context.read<ActivityBloc>().add(SearchActivities(
|
||||
tripId: widget.trip.id!,
|
||||
destination: widget.trip.location,
|
||||
category: null,
|
||||
maxResults: newTotal, // Demander le total cumulé
|
||||
reset: true, // Reset pour avoir tous les résultats d'un coup
|
||||
));
|
||||
print(
|
||||
'⚠️ [Google Search] No coordinates available, falling back to destination geocoding',
|
||||
);
|
||||
context.read<ActivityBloc>().add(
|
||||
SearchActivities(
|
||||
tripId: widget.trip.id!,
|
||||
destination: widget.trip.location,
|
||||
category: null,
|
||||
maxResults: newTotal, // Demander le total cumulé
|
||||
reset: true, // Reset pour avoir tous les résultats d'un coup
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _loadMoreGoogleActivitiesWithTotal(int totalToRequest) {
|
||||
print('📈 [Google Search] Loading activities with specific total: $totalToRequest');
|
||||
print(
|
||||
'📈 [Google Search] Loading activities with specific total: $totalToRequest',
|
||||
);
|
||||
|
||||
// Au lieu de reset, on utilise l'offset et append pour forcer plus de résultats
|
||||
final currentState = context.read<ActivityBloc>().state;
|
||||
@@ -1381,31 +1524,41 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
final currentCount = currentState.searchResults.length;
|
||||
final additionalNeeded = totalToRequest - currentCount;
|
||||
|
||||
print('📊 [Google Search] Current: $currentCount, Total demandé: $totalToRequest, Additional: $additionalNeeded');
|
||||
print(
|
||||
'📊 [Google Search] Current: $currentCount, Total demandé: $totalToRequest, Additional: $additionalNeeded',
|
||||
);
|
||||
|
||||
if (additionalNeeded > 0) {
|
||||
// Utiliser les coordonnées pré-géolocalisées du voyage si disponibles
|
||||
if (widget.trip.hasCoordinates) {
|
||||
print('🌍 [Google Search] Using pre-geocoded coordinates for additional results');
|
||||
context.read<ActivityBloc>().add(SearchActivitiesWithCoordinates(
|
||||
tripId: widget.trip.id!,
|
||||
latitude: widget.trip.latitude!,
|
||||
longitude: widget.trip.longitude!,
|
||||
category: null,
|
||||
maxResults: additionalNeeded,
|
||||
offset: currentCount,
|
||||
appendToExisting: true, // Ajouter aux résultats existants
|
||||
));
|
||||
print(
|
||||
'🌍 [Google Search] Using pre-geocoded coordinates for additional results',
|
||||
);
|
||||
context.read<ActivityBloc>().add(
|
||||
SearchActivitiesWithCoordinates(
|
||||
tripId: widget.trip.id!,
|
||||
latitude: widget.trip.latitude!,
|
||||
longitude: widget.trip.longitude!,
|
||||
category: null,
|
||||
maxResults: additionalNeeded,
|
||||
offset: currentCount,
|
||||
appendToExisting: true, // Ajouter aux résultats existants
|
||||
),
|
||||
);
|
||||
} else {
|
||||
print('⚠️ [Google Search] No coordinates available, falling back to destination geocoding');
|
||||
context.read<ActivityBloc>().add(SearchActivities(
|
||||
tripId: widget.trip.id!,
|
||||
destination: widget.trip.location,
|
||||
category: null,
|
||||
maxResults: additionalNeeded,
|
||||
offset: currentCount,
|
||||
appendToExisting: true, // Ajouter aux résultats existants
|
||||
));
|
||||
print(
|
||||
'⚠️ [Google Search] No coordinates available, falling back to destination geocoding',
|
||||
);
|
||||
context.read<ActivityBloc>().add(
|
||||
SearchActivities(
|
||||
tripId: widget.trip.id!,
|
||||
destination: widget.trip.location,
|
||||
category: null,
|
||||
maxResults: additionalNeeded,
|
||||
offset: currentCount,
|
||||
appendToExisting: true, // Ajouter aux résultats existants
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
print('⚠️ [Google Search] Pas besoin de charger plus (déjà suffisant)');
|
||||
@@ -1413,24 +1566,32 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
} else {
|
||||
// Si pas de résultats existants, faire une recherche complète
|
||||
if (widget.trip.hasCoordinates) {
|
||||
print('🌍 [Google Search] Using pre-geocoded coordinates for fresh search');
|
||||
context.read<ActivityBloc>().add(SearchActivitiesWithCoordinates(
|
||||
tripId: widget.trip.id!,
|
||||
latitude: widget.trip.latitude!,
|
||||
longitude: widget.trip.longitude!,
|
||||
category: null,
|
||||
maxResults: totalToRequest,
|
||||
reset: true,
|
||||
));
|
||||
print(
|
||||
'🌍 [Google Search] Using pre-geocoded coordinates for fresh search',
|
||||
);
|
||||
context.read<ActivityBloc>().add(
|
||||
SearchActivitiesWithCoordinates(
|
||||
tripId: widget.trip.id!,
|
||||
latitude: widget.trip.latitude!,
|
||||
longitude: widget.trip.longitude!,
|
||||
category: null,
|
||||
maxResults: totalToRequest,
|
||||
reset: true,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
print('⚠️ [Google Search] No coordinates available, falling back to destination geocoding');
|
||||
context.read<ActivityBloc>().add(SearchActivities(
|
||||
tripId: widget.trip.id!,
|
||||
destination: widget.trip.location,
|
||||
category: null,
|
||||
maxResults: totalToRequest,
|
||||
reset: true,
|
||||
));
|
||||
print(
|
||||
'⚠️ [Google Search] No coordinates available, falling back to destination geocoding',
|
||||
);
|
||||
context.read<ActivityBloc>().add(
|
||||
SearchActivities(
|
||||
tripId: widget.trip.id!,
|
||||
destination: widget.trip.location,
|
||||
category: null,
|
||||
maxResults: totalToRequest,
|
||||
reset: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
@@ -47,12 +44,7 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
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),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -241,16 +237,16 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(
|
||||
color: isDarkMode
|
||||
? Colors.white.withOpacity(0.2)
|
||||
: Colors.black.withOpacity(0.2),
|
||||
? 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),
|
||||
? Colors.white.withOpacity(0.2)
|
||||
: Colors.black.withOpacity(0.2),
|
||||
),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
@@ -271,9 +267,7 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
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,
|
||||
@@ -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(
|
||||
@@ -313,16 +312,16 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
_getCategoryIcon(category),
|
||||
size: 16,
|
||||
color: isSelected
|
||||
? Colors.white
|
||||
: theme.colorScheme.onSurface,
|
||||
? Colors.white
|
||||
: theme.colorScheme.onSurface,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
category.displayName,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: isSelected
|
||||
? Colors.white
|
||||
: theme.colorScheme.onSurface,
|
||||
? Colors.white
|
||||
: theme.colorScheme.onSurface,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
@@ -362,8 +361,8 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
description: _descriptionController.text.trim(),
|
||||
category: _selectedCategory.displayName,
|
||||
address: _addressController.text.trim().isNotEmpty
|
||||
? _addressController.text.trim()
|
||||
: null,
|
||||
? _addressController.text.trim()
|
||||
: null,
|
||||
votes: {},
|
||||
createdAt: DateTime.now(),
|
||||
updatedAt: DateTime.now(),
|
||||
@@ -373,7 +372,6 @@ class _AddActivityBottomSheetState extends State<AddActivityBottomSheet> {
|
||||
|
||||
// Fermer le bottom sheet
|
||||
Navigator.pop(context);
|
||||
|
||||
} catch (e) {
|
||||
_errorService.showSnackbar(
|
||||
message: 'Erreur lors de l\'ajout de l\'activité',
|
||||
|
||||
@@ -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();
|
||||
@@ -45,14 +41,15 @@ class _TripCardState extends State<TripCard> {
|
||||
});
|
||||
|
||||
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(() {
|
||||
@@ -118,11 +115,10 @@ class _TripCardState extends State<TripCard> {
|
||||
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),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
@@ -214,7 +210,10 @@ class _TripCardState extends State<TripCard> {
|
||||
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> {
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -183,7 +183,7 @@ class Activity {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Activity(id: $id, name: $name, category: $category, votes: ${totalVotes})';
|
||||
return 'Activity(id: $id, name: $name, category: $category, votes: $totalVotes)';
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import 'dart:io';
|
||||
import '../lib/services/trip_image_service.dart';
|
||||
import 'package:travel_mate/services/trip_image_service.dart';
|
||||
|
||||
/// Script utilitaire pour nettoyer les images inutilisées
|
||||
/// À exécuter manuellement si nécessaire
|
||||
void main() async {
|
||||
|
||||
try {
|
||||
final tripImageService = TripImageService();
|
||||
|
||||
@@ -18,15 +17,11 @@ void main() async {
|
||||
|
||||
final stats = await tripImageService.getImageStatistics(userId);
|
||||
|
||||
|
||||
if (stats['tripsWithImages'] > 0) {
|
||||
await tripImageService.cleanupUnusedImages(userId);
|
||||
|
||||
final newStats = await tripImageService.getImageStatistics(userId);
|
||||
} else {
|
||||
}
|
||||
|
||||
|
||||
} else {}
|
||||
} catch (e) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import 'package:firebase_core/firebase_core.dart';
|
||||
import 'package:firebase_storage/firebase_storage.dart';
|
||||
import '../lib/firebase_options.dart';
|
||||
import 'package:travel_mate/firebase_options.dart';
|
||||
|
||||
/// Script de diagnostic pour analyser les images dans Firebase Storage
|
||||
void main() async {
|
||||
|
||||
try {
|
||||
// Initialiser Firebase
|
||||
await Firebase.initializeApp(
|
||||
@@ -19,30 +18,30 @@ void main() async {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
final Map<String, List<Map<String, dynamic>>> locationGroups = {};
|
||||
|
||||
for (int i = 0; i < listResult.items.length; i++) {
|
||||
final item = listResult.items[i];
|
||||
final fileName = item.name;
|
||||
|
||||
|
||||
try {
|
||||
// Récupérer les métadonnées
|
||||
final metadata = await item.getMetadata();
|
||||
final customMeta = metadata.customMetadata ?? {};
|
||||
|
||||
final location = customMeta['location'] ?? 'Inconnue';
|
||||
final normalizedLocation = customMeta['normalizedLocation'] ?? 'Non définie';
|
||||
final normalizedLocation =
|
||||
customMeta['normalizedLocation'] ?? 'Non définie';
|
||||
final source = customMeta['source'] ?? 'Inconnue';
|
||||
final uploadedAt = customMeta['uploadedAt'] ?? 'Inconnue';
|
||||
|
||||
|
||||
// Récupérer l'URL de téléchargement
|
||||
final downloadUrl = await item.getDownloadURL();
|
||||
|
||||
// Grouper par location normalisée
|
||||
final groupKey = normalizedLocation != 'Non définie' ? normalizedLocation : location.toLowerCase();
|
||||
final groupKey = normalizedLocation != 'Non définie'
|
||||
? normalizedLocation
|
||||
: location.toLowerCase();
|
||||
if (!locationGroups.containsKey(groupKey)) {
|
||||
locationGroups[groupKey] = [];
|
||||
}
|
||||
@@ -53,9 +52,7 @@ void main() async {
|
||||
'uploadedAt': uploadedAt,
|
||||
'downloadUrl': downloadUrl,
|
||||
});
|
||||
|
||||
} catch (e) {
|
||||
|
||||
// Essayer de deviner la location depuis le nom du fichier
|
||||
final parts = fileName.split('_');
|
||||
if (parts.length >= 2) {
|
||||
@@ -73,7 +70,6 @@ void main() async {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Analyser les doublons
|
||||
@@ -89,14 +85,9 @@ void main() async {
|
||||
for (int i = 0; i < images.length; i++) {
|
||||
final image = images[i];
|
||||
}
|
||||
} else {
|
||||
}
|
||||
} else {}
|
||||
}
|
||||
|
||||
|
||||
if (totalDuplicates > 0) {
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
}
|
||||
if (totalDuplicates > 0) {}
|
||||
} catch (e) {}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ void main() {
|
||||
|
||||
// Scénario 1: Premier chargement (aucune image existante)
|
||||
print('=== Scénario 1: Premier chargement ===');
|
||||
String? existingImage = null; // Aucune image dans le Storage
|
||||
String? existingImage; // Aucune image dans le Storage
|
||||
|
||||
if (existingImage == null) {
|
||||
print('✓ Aucune image existante trouvée');
|
||||
@@ -30,7 +30,8 @@ void main() {
|
||||
|
||||
// Scénario 3: Différente destination
|
||||
print('\n=== Scénario 3: Destination différente ===');
|
||||
String? differentLocationImage = null; // Pas d'image pour cette nouvelle destination
|
||||
String?
|
||||
differentLocationImage; // Pas d'image pour cette nouvelle destination
|
||||
|
||||
if (differentLocationImage == null) {
|
||||
print('✓ Nouvelle destination, aucune image existante');
|
||||
@@ -52,9 +53,15 @@ void main() {
|
||||
final testCases = [
|
||||
{'input': 'Paris, France', 'expected': 'paris_france'},
|
||||
{'input': 'New York City', 'expected': 'new_york_city'},
|
||||
{'input': 'São Paulo', 'expected': 's_o_paulo'}, // Caractères spéciaux remplacés
|
||||
{
|
||||
'input': 'São Paulo',
|
||||
'expected': 's_o_paulo',
|
||||
}, // Caractères spéciaux remplacés
|
||||
{'input': 'Londres, Royaume-Uni', 'expected': 'londres_royaume_uni'},
|
||||
{'input': 'Tokyo (東京)', 'expected': 'tokyo'}, // Caractères non-latins supprimés
|
||||
{
|
||||
'input': 'Tokyo (東京)',
|
||||
'expected': 'tokyo',
|
||||
}, // Caractères non-latins supprimés
|
||||
];
|
||||
|
||||
for (final testCase in testCases) {
|
||||
@@ -68,17 +75,17 @@ void main() {
|
||||
// Simulation des bénéfices de performance
|
||||
|
||||
final oldSystem = {
|
||||
'apiCalls': 4, // 4 appels à chaque chargement
|
||||
'storageWrites': 4, // 4 écritures dans le Storage
|
||||
'storageReads': 0, // Pas de vérification existante
|
||||
'dataUsage': '4.8 MB', // 4 images × 1.2 MB chacune
|
||||
'apiCalls': 4, // 4 appels à chaque chargement
|
||||
'storageWrites': 4, // 4 écritures dans le Storage
|
||||
'storageReads': 0, // Pas de vérification existante
|
||||
'dataUsage': '4.8 MB', // 4 images × 1.2 MB chacune
|
||||
};
|
||||
|
||||
final newSystem = {
|
||||
'apiCalls': 2, // Seulement pour les nouvelles destinations
|
||||
'storageWrites': 2, // Seulement pour les nouvelles images
|
||||
'storageReads': 2, // Vérifications d'existence
|
||||
'dataUsage': '2.4 MB', // Seulement 2 images nécessaires
|
||||
'apiCalls': 2, // Seulement pour les nouvelles destinations
|
||||
'storageWrites': 2, // Seulement pour les nouvelles images
|
||||
'storageReads': 2, // Vérifications d'existence
|
||||
'dataUsage': '2.4 MB', // Seulement 2 images nécessaires
|
||||
};
|
||||
|
||||
print('=== Comparaison de performance ===');
|
||||
|
||||
@@ -30,8 +30,10 @@ void main() {
|
||||
final height = photo['height'] as int;
|
||||
final ratio = width / height;
|
||||
final resolution = width * height;
|
||||
print('${photo['photo_reference']}: ${width}x${height} '
|
||||
'(ratio: ${ratio.toStringAsFixed(2)}, résolution: $resolution)');
|
||||
print(
|
||||
'${photo['photo_reference']}: ${width}x$height '
|
||||
'(ratio: ${ratio.toStringAsFixed(2)}, résolution: $resolution)',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -44,7 +46,10 @@ void main() {
|
||||
expect(searchTerms.any((term) => term.contains('Notre-Dame')), true);
|
||||
|
||||
// Vérifier que les termes génériques sont aussi présents
|
||||
expect(searchTerms.any((term) => term.contains('attractions touristiques')), true);
|
||||
expect(
|
||||
searchTerms.any((term) => term.contains('attractions touristiques')),
|
||||
true,
|
||||
);
|
||||
expect(searchTerms.any((term) => term.contains('landmarks')), true);
|
||||
|
||||
print('Termes de recherche pour Paris:');
|
||||
@@ -72,7 +77,10 @@ void main() {
|
||||
|
||||
// Devrait au moins avoir des termes génériques
|
||||
expect(searchTerms.isNotEmpty, true);
|
||||
expect(searchTerms.any((term) => term.contains('attractions touristiques')), true);
|
||||
expect(
|
||||
searchTerms.any((term) => term.contains('attractions touristiques')),
|
||||
true,
|
||||
);
|
||||
expect(searchTerms.any((term) => term.contains('landmarks')), true);
|
||||
|
||||
// Le terme original devrait être en dernier
|
||||
|
||||
Reference in New Issue
Block a user