From ca28e0a7806c91ed41ae222123772931ee10f3a8 Mon Sep 17 00:00:00 2001 From: Van Leemput Dayron Date: Sat, 6 Dec 2025 14:43:22 +0100 Subject: [PATCH] feat: Implement platform-specific Google Maps API key handling and update app version. --- lib/components/home/create_trip_content.dart | 14 +++++++++++++- lib/components/map/map_content.dart | 14 +++++++++++++- lib/services/activity_places_service.dart | 15 ++++++++++++++- lib/services/place_image_service.dart | 15 ++++++++++++++- lib/services/trip_geocoding_service.dart | 14 +++++++++++++- pubspec.yaml | 2 +- 6 files changed, 68 insertions(+), 6 deletions(-) diff --git a/lib/components/home/create_trip_content.dart b/lib/components/home/create_trip_content.dart index 9649fb5..d0ceb82 100644 --- a/lib/components/home/create_trip_content.dart +++ b/lib/components/home/create_trip_content.dart @@ -1,3 +1,4 @@ +import 'dart:io'; import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -84,7 +85,18 @@ class _CreateTripContentState extends State { String? _selectedImageUrl; /// Google Maps API key for location services - static final String _apiKey = dotenv.env['GOOGLE_MAPS_API_KEY'] ?? ''; + static String get _apiKey { + if (Platform.isAndroid) { + return dotenv.env['GOOGLE_MAPS_API_KEY_ANDROID'] ?? + dotenv.env['GOOGLE_MAPS_API_KEY'] ?? + ''; + } else if (Platform.isIOS) { + return dotenv.env['GOOGLE_MAPS_API_KEY_IOS'] ?? + dotenv.env['GOOGLE_MAPS_API_KEY'] ?? + ''; + } + return dotenv.env['GOOGLE_MAPS_API_KEY'] ?? ''; + } /// Participant management final List _participants = []; diff --git a/lib/components/map/map_content.dart b/lib/components/map/map_content.dart index c3d033a..ceb5c82 100644 --- a/lib/components/map/map_content.dart +++ b/lib/components/map/map_content.dart @@ -1,3 +1,4 @@ +import 'dart:io'; import 'package:flutter/material.dart'; import 'package:google_maps_flutter/google_maps_flutter.dart'; import 'package:geolocator/geolocator.dart'; @@ -31,7 +32,18 @@ class _MapContentState extends State { List _suggestions = []; - static final String _apiKey = dotenv.env['GOOGLE_MAPS_API_KEY'] ?? ''; + static String get _apiKey { + if (Platform.isAndroid) { + return dotenv.env['GOOGLE_MAPS_API_KEY_ANDROID'] ?? + dotenv.env['GOOGLE_MAPS_API_KEY'] ?? + ''; + } else if (Platform.isIOS) { + return dotenv.env['GOOGLE_MAPS_API_KEY_IOS'] ?? + dotenv.env['GOOGLE_MAPS_API_KEY'] ?? + ''; + } + return dotenv.env['GOOGLE_MAPS_API_KEY'] ?? ''; + } @override void initState() { diff --git a/lib/services/activity_places_service.dart b/lib/services/activity_places_service.dart index aeaa64a..b45351a 100644 --- a/lib/services/activity_places_service.dart +++ b/lib/services/activity_places_service.dart @@ -1,3 +1,4 @@ +import 'dart:io'; import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:flutter_dotenv/flutter_dotenv.dart'; @@ -13,7 +14,19 @@ class ActivityPlacesService { ActivityPlacesService._internal(); final ErrorService _errorService = ErrorService(); - static final String _apiKey = dotenv.env['GOOGLE_MAPS_API_KEY'] ?? ''; + + static String get _apiKey { + if (Platform.isAndroid) { + return dotenv.env['GOOGLE_MAPS_API_KEY_ANDROID'] ?? + dotenv.env['GOOGLE_MAPS_API_KEY'] ?? + ''; + } else if (Platform.isIOS) { + return dotenv.env['GOOGLE_MAPS_API_KEY_IOS'] ?? + dotenv.env['GOOGLE_MAPS_API_KEY'] ?? + ''; + } + return dotenv.env['GOOGLE_MAPS_API_KEY'] ?? ''; + } /// Recherche des activités près d'une destination Future> searchActivities({ diff --git a/lib/services/place_image_service.dart b/lib/services/place_image_service.dart index 80c73da..5b99602 100644 --- a/lib/services/place_image_service.dart +++ b/lib/services/place_image_service.dart @@ -1,3 +1,4 @@ +import 'dart:io'; import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:flutter_dotenv/flutter_dotenv.dart'; @@ -5,7 +6,19 @@ import 'package:firebase_storage/firebase_storage.dart'; import 'package:travel_mate/services/error_service.dart'; class PlaceImageService { - static final String _apiKey = dotenv.env['GOOGLE_MAPS_API_KEY'] ?? ''; + static String get _apiKey { + if (Platform.isAndroid) { + return dotenv.env['GOOGLE_MAPS_API_KEY_ANDROID'] ?? + dotenv.env['GOOGLE_MAPS_API_KEY'] ?? + ''; + } else if (Platform.isIOS) { + return dotenv.env['GOOGLE_MAPS_API_KEY_IOS'] ?? + dotenv.env['GOOGLE_MAPS_API_KEY'] ?? + ''; + } + return dotenv.env['GOOGLE_MAPS_API_KEY'] ?? ''; + } + final FirebaseStorage _storage = FirebaseStorage.instance; final ErrorService _errorService = ErrorService(); diff --git a/lib/services/trip_geocoding_service.dart b/lib/services/trip_geocoding_service.dart index 685f0d8..45732d2 100644 --- a/lib/services/trip_geocoding_service.dart +++ b/lib/services/trip_geocoding_service.dart @@ -1,3 +1,4 @@ +import 'dart:io'; import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:flutter_dotenv/flutter_dotenv.dart'; @@ -13,7 +14,18 @@ class TripGeocodingService { TripGeocodingService._internal(); final ErrorService _errorService = ErrorService(); - static final String _apiKey = dotenv.env['GOOGLE_MAPS_API_KEY'] ?? ''; + static String get _apiKey { + if (Platform.isAndroid) { + return dotenv.env['GOOGLE_MAPS_API_KEY_ANDROID'] ?? + dotenv.env['GOOGLE_MAPS_API_KEY'] ?? + ''; + } else if (Platform.isIOS) { + return dotenv.env['GOOGLE_MAPS_API_KEY_IOS'] ?? + dotenv.env['GOOGLE_MAPS_API_KEY'] ?? + ''; + } + return dotenv.env['GOOGLE_MAPS_API_KEY'] ?? ''; + } /// Géocode la destination d'un voyage et retourne un Trip mis à jour Future geocodeTrip(Trip trip) async { diff --git a/pubspec.yaml b/pubspec.yaml index 5fe6d47..890a0e1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.0+1 +version: 1.0.1+2 environment: sdk: ^3.9.2