Presearch google activities.
This commit is contained in:
@@ -5,6 +5,7 @@ import '../../blocs/activity/activity_event.dart';
|
||||
import '../../blocs/activity/activity_state.dart';
|
||||
import '../../models/trip.dart';
|
||||
import '../../models/activity.dart';
|
||||
import '../../services/activity_cache_service.dart';
|
||||
import '../activities/add_activity_bottom_sheet.dart';
|
||||
|
||||
class ActivitiesPage extends StatefulWidget {
|
||||
@@ -20,6 +21,7 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
|
||||
late TabController _tabController;
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final ActivityCacheService _cacheService = ActivityCacheService();
|
||||
String _selectedCategory = 'Toutes les catégories';
|
||||
String _selectedPrice = 'Prix';
|
||||
String _selectedRating = 'Note';
|
||||
@@ -79,7 +81,18 @@ class _ActivitiesPageState extends State<ActivitiesPage>
|
||||
void _handleTabChange() {
|
||||
// Si on va sur l'onglet suggestions Google et qu'aucune recherche n'a été faite
|
||||
if (_tabController.index == 2 && !_googleSearchPerformed) {
|
||||
_searchGoogleActivities();
|
||||
// Vérifier si on a des activités en cache
|
||||
final cachedActivities = _cacheService.getCachedActivities(widget.trip.id!);
|
||||
if (cachedActivities != null && cachedActivities.isNotEmpty) {
|
||||
// Restaurer les activités en cache dans le BLoC
|
||||
context.read<ActivityBloc>().add(
|
||||
RestoreCachedSearchResults(searchResults: cachedActivities),
|
||||
);
|
||||
_googleSearchPerformed = true;
|
||||
} else {
|
||||
// Sinon, faire une nouvelle recherche
|
||||
_searchGoogleActivities();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class ActivityCard extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
color: Colors.black.withValues(alpha: 0.05),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
@@ -74,7 +74,7 @@ class ActivityCard extends StatelessWidget {
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withOpacity(0.7),
|
||||
color: Colors.black.withValues(alpha: 0.7),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:travel_mate/blocs/trip/trip_bloc.dart';
|
||||
import 'package:travel_mate/blocs/trip/trip_event.dart';
|
||||
import 'package:travel_mate/blocs/activity/activity_bloc.dart';
|
||||
import 'package:travel_mate/blocs/activity/activity_event.dart';
|
||||
import 'package:travel_mate/components/home/create_trip_content.dart';
|
||||
import 'package:travel_mate/models/trip.dart';
|
||||
import 'package:travel_mate/components/map/map_content.dart';
|
||||
import 'package:travel_mate/services/error_service.dart';
|
||||
import 'package:travel_mate/services/activity_cache_service.dart';
|
||||
import 'package:travel_mate/components/activities/activities_page.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
@@ -19,6 +23,47 @@ class ShowTripDetailsContent extends StatefulWidget {
|
||||
|
||||
class _ShowTripDetailsContentState extends State<ShowTripDetailsContent> {
|
||||
final ErrorService _errorService = ErrorService();
|
||||
final ActivityCacheService _cacheService = ActivityCacheService();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Lancer la recherche d'activités Google en arrière-plan
|
||||
_preloadGoogleActivities();
|
||||
}
|
||||
|
||||
/// Précharger les activités Google en arrière-plan
|
||||
void _preloadGoogleActivities() {
|
||||
// Attendre un moment avant de lancer la recherche pour ne pas bloquer l'UI
|
||||
Future.delayed(const Duration(milliseconds: 500), () {
|
||||
if (mounted && widget.trip.id != null) {
|
||||
// Vérifier si on a déjà des activités en cache
|
||||
if (_cacheService.hasCachedActivities(widget.trip.id!)) {
|
||||
return; // Utiliser le cache
|
||||
}
|
||||
|
||||
// Sinon, lancer la recherche
|
||||
context.read<ActivityBloc>().add(
|
||||
widget.trip.hasCoordinates
|
||||
? SearchActivitiesWithCoordinates(
|
||||
tripId: widget.trip.id!,
|
||||
latitude: widget.trip.latitude!,
|
||||
longitude: widget.trip.longitude!,
|
||||
category: null,
|
||||
maxResults: 6,
|
||||
reset: true,
|
||||
)
|
||||
: SearchActivities(
|
||||
tripId: widget.trip.id!,
|
||||
destination: widget.trip.location,
|
||||
category: null,
|
||||
maxResults: 6,
|
||||
reset: true,
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Calculer les jours restants avant le voyage
|
||||
int get daysUntilTrip {
|
||||
|
||||
Reference in New Issue
Block a user