Adds complete Google Navigation support with: - LocationPermissionService for runtime location permissions - NavigationSessionService for session and route management - NavigationPage for full-screen turn-by-turn navigation UI - NavigationTermsAndConditionsDialog for service acceptance - Comprehensive i18n support (English/French) - Android minSdk=23 with Java NIO desugaring - iOS location permissions in Info.plist - Error handling with user-friendly dialogs - Location update and arrival notifications Includes detailed setup guide and implementation documentation with API key configuration instructions, integration examples, and testing checklist. Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
8.0 KiB
Google Navigation Flutter - Implementation Summary
Overview
Complete implementation of Google Navigation Flutter for the Plan B Logistics app with full support for turn-by-turn navigation, location permissions, and internationalization.
Configuration Changes
Android (android/app/build.gradle.kts)
- Set
minSdk = 23(required for Google Navigation) - Added desugaring dependency for Java NIO support
- Kotlin version already at 2.1.0 (meets 2.0+ requirement)
iOS (ios/Runner/Info.plist)
- Added
NSLocationAlwaysUsageDescriptionfor background location tracking - Background modes already configured for location
- API key already configured in AppDelegate.swift
New Services Created
1. LocationPermissionService (lib/services/location_permission_service.dart)
Handles location permission requests with pattern matching:
requestLocationPermission()- Request user permissionhasLocationPermission()- Check current statusopenAppSettings()- Open app settings
Returns LocationPermissionResult sealed class with states:
granted()- Permission granteddenied()- Permission deniedpermanentlyDenied()- Need to open settingserror(message)- System error occurred
2. NavigationSessionService (lib/services/navigation_session_service.dart)
Singleton service for managing Google Navigation session:
initializeSession()- Initialize navigation sessionsetController(controller)- Set view controllercalculateRoute(...)- Calculate route from A to BstartNavigation()- Start turn-by-turn guidancestopNavigation()- Stop current navigationaddLocationListener(callback)- Track location updatesaddArrivalListener(callback)- Handle destination arrivaladdRemainingDistanceListener(callback)- Track remaining distancecleanup()- Cleanup resources
Returns NavigationRoute with location and route info.
New UI Components
1. NavigationTermsAndConditionsDialog (lib/components/navigation_tc_dialog.dart)
Material 3 themed dialog for T&C acceptance:
- Displays navigation service description
- Shows Google Maps attribution
- Accept/Decline buttons with callbacks
- Fully internationalized
2. NavigationPage (lib/pages/navigation_page.dart)
Complete turn-by-turn navigation screen:
- Full-screen Google Navigation View
- Automatic location permission handling
- Destination markers and route visualization
- Navigation UI controls enabled
- Arrival notifications
- Error handling dialogs
- Loading states with spinners
Features:
- Initializes navigation session
- Requests location permissions if needed
- Sets delivery destination
- Shows T&C dialog on first use
- Handles navigation events (arrival, location updates)
- Provides completion/cancellation callbacks
Internationalization
Added translation keys for both English and French:
Navigation Service Keys
navigationTcTitle- Service namenavigationTcDescription- Service descriptionnavigationTcAttribution- Google Maps attributionnavigationTcTerms- Terms acceptance text
Permission Keys
locationPermissionRequired- TitlelocationPermissionMessage- Permission request messagelocationPermissionDenied- Denial messagepermissionPermanentlyDenied- Title for settings neededopenSettingsMessage- Settings messageopenSettings- Open settings button
Navigation Keys
navigationArrived- Arrival notificationnavigatingTo- Navigation header textinitializingNavigation- Loading message
General Keys
accept,decline- Button labelscancel,ok,requestPermission- Common buttons
File Structure
lib/
├── services/
│ ├── location_permission_service.dart (NEW)
│ ├── navigation_session_service.dart (NEW)
│ └── auth_service.dart (existing)
├── pages/
│ ├── navigation_page.dart (NEW)
│ ├── deliveries_page.dart (existing)
│ └── ...
├── components/
│ ├── navigation_tc_dialog.dart (NEW)
│ └── ...
└── l10n/
├── app_en.arb (UPDATED)
└── app_fr.arb (UPDATED)
android/
└── app/
└── build.gradle.kts (UPDATED)
ios/
├── Podfile (already configured)
└── Runner/
└── Info.plist (UPDATED)
Key Features Implemented
-
Location Permissions
- Runtime permission request with user dialogs
- Handles denied and permanently denied states
- Opens app settings for permanently denied case
- Uses permission_handler package
-
Navigation Session Management
- Singleton pattern for session lifecycle
- Route calculation from start to destination
- Event listeners for location and arrival
- Proper error handling with custom exceptions
-
Turn-by-Turn Navigation
- Full-screen Google Navigation View
- Real-time location tracking
- Destination arrival notifications
- Navigation UI with zoom and scroll controls
- Marker clustering for multiple waypoints
-
User Dialogs
- Location permission request
- T&C acceptance for navigation services
- Error notifications
- Settings access for denied permissions
-
Error Handling
- Initialization errors
- Permission errors
- Route calculation failures
- Navigation start/stop errors
- User-friendly error messages
Integration Steps
To integrate into deliveries page:
// Add navigation button to delivery item
FloatingActionButton(
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => NavigationPage(
delivery: delivery,
destinationLatitude: delivery.latitude,
destinationLongitude: delivery.longitude,
onNavigationComplete: () {
// Update delivery status
ref.refresh(deliveriesProvider(routeFragmentId));
},
),
),
),
child: const Icon(Icons.navigation),
)
Configuration Requirements
Before testing/releasing:
-
Add API Keys
- Android: Add to AndroidManifest.xml or build.gradle
- iOS: Update AppDelegate.swift (already configured)
-
Update AndroidManifest.xml (if not using build.gradle)
<meta-data android:name="com.google.android.geo.API_KEY" android:value="YOUR_API_KEY" /> -
Verify Permissions in AndroidManifest.xml
INTERNETACCESS_FINE_LOCATIONACCESS_COARSE_LOCATION
-
Test on Devices
- Android 6.0+ (API 23+)
- iOS 16.0+
- Real devices (emulator may have limited GPS)
Design System Compliance
All components follow Svrnty design system:
- Material 3 theme colors (Primary: #C44D58, Secondary: #475C6C)
- Montserrat typography
- Dark/light theme support
- High contrast variants compatible
Code Quality
- Strict typing enforced (no
dynamicor untypedvar) - Sealed classes for type-safe pattern matching
- Result pattern for error handling
- Proper resource cleanup in dispose
- Comprehensive null safety
Testing Recommendations
Android
- Test on API 23+ device
- Verify GPS works
- Check location permission dialog
- Verify navigation UI displays correctly
- Test arrival notifications
iOS
- Test on iOS 16.0+ device
- Verify location permission dialog
- Check background location mode
- Test with navigation UI
- Verify arrival notification
Known Limitations
- Package is in Beta (expect potential breaking changes)
- Don't combine with other Google Maps SDK versions
- EEA developers subject to regional terms (effective July 8, 2025)
- Navigation requires actual GPS for best results
Documentation
Comprehensive setup guide provided in GOOGLE_NAVIGATION_SETUP.md including:
- API key configuration for both platforms
- Integration examples
- Service usage documentation
- Error handling patterns
- Production considerations
- Testing checklist
Next Steps
- Add your Google Cloud API keys
- Test location permissions flow
- Integrate navigation button into delivery items
- Test on real Android and iOS devices
- Monitor navigation start/completion rates
- Gather user feedback on navigation experience