Demonstrates how to use the google_driver_flutter plugin.
Driver SDK example app requires a backend services to be running. The backend services are provided as Docker containers. To start the backend services, read the documentation in the tools/backend folder of the example app.
To run the example project, you need to provide your Google Maps API key for both Android and iOS platforms.
Both Android and iOS builds are able to use the MAPS_API_KEY variable provided through Dart defines.
However, this can be overridden to use separate, platform-specific API keys if needed.
Using Dart defines to provide the Google Maps API key is the preferred method for this example app. It allows the key to be utilized in Dart code for accessing Google Maps services, such as the Routes API. Additionally, Patrol integration tests should also be run with the API key provided via Dart defines.
Run the app with the API key as a Dart define.
flutter run --dart-define MAPS_API_KEY=YOUR_API_KEY --dart-define PROJECT_ID=YOUR_PROJECT_IDThe example app demonstrates multiple ways to provide the Maps API key for platforms.
For Android, the example app determines the MAPS_API_KEY using the following order (first match applies):
MAPS_API_KEYvariable inlocal.propertiesfileMAPS_API_KEYvariable in environment variablesMAPS_API_KEYvariable in Dart defines
The project uses the Google Maps Secrets Gradle Plugin for secure API key management. Place your Google Maps API key in example/android/local.properties file in the following format:
MAPS_API_KEY=YOUR_API_KEY_HERE
This key will be specifically used for the Android build, overriding the Dart define value.
Note
local.properties file should always be listed in your .gitignore file to ensure it is not committed to your repository.
For iOS, the app attempts to read the MAPS_API_KEY in this order (first match applies):
MAPS_API_KEYvariable in Xcode environment variablesMAPS_API_KEYvariable in Dart defines- Default API key from
AppDelegate.swift.
1. Option: Xcode Environment Variables
Add an environment variable named MAPS_API_KEY in the Xcode scheme settings.
2. Option: Directly in AppDelegate.swift
Set the API key directly in example/ios/Runner/AppDelegate.swift:
...
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GMSServices.provideAPIKey("YOUR_API_KEY") // REPLACE THIS TEXT WITH YOUR API KEY
GMSServices.setMetalRendererEnabled(true)
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
...Note
Be cautious with API keys. Avoid exposing them in public repositories, especially when hardcoded in the project files or the environment variables.
To run the example app, follow these steps:
- Start sample backends as described in the Starting example app backend services section.
- Start the emulator or connect your device.
- Run the following command from the root of the example project:
cd example flutter run --dart-define MAPS_API_KEY=YOUR_API_KEY --dart-define PROJECT_ID=YOUR_PROJECT_ID
If you want to run the example app with a specific API key, see the Setting up API Keys section.
[!TIP](Pod-related issues on iOS) If you encounter pod-related issues when running the example code on iOS, you can try running the following commands from the
example/iosfolder:
- pod repo update
- pod install
These commands will update and install the required pod files specifically for iOS.
Supported dart define values and their default values:
| Dart define | Description | Default value |
|---|---|---|
MAPS_API_KEY |
Google Maps API key | null |
PROJECT_ID |
Firebase project ID | null |
LMFS_ANDROID_HOST_URL |
Android sample backend services base URL for Delivery Driver (LMFS) | http://10.0.2.2:8091 |
LMFS_IOS_HOST_URL |
iOS backend sample services base URL for Delivery Driver (LMFS) | http://localhost:8091 |
ODRD_ANDROID_HOST_URL |
Android backend sample services base URL for Ridesharing Driver (ODRD) | http://10.0.2.2:8092 |
ODRD_IOS_HOST_URL |
iOS backend sample services base URL for Ridesharing Driver (ODRD) | http://localhost:8092 |
When running the example app on physical devices, you need to replace the localhost and 10.0.2.2 with the IP address of the machine running the backend services.
Build the flutter example app with following command:
cd example
flutter run \
--dart-define LMFS_ANDROID_HOST_URL=http://YOUR_MACHINE_IP:8091 \
--dart-define LMFS_IOS_HOST_URL=http://YOUR_MACHINE_IP:8091 \
--dart-define ODRD_ANDROID_HOST_URL=http://YOUR_MACHINE_IP:8092 \
--dart-define ODRD_IOS_HOST_URL=http://YOUR_MACHINE_IP:8092 \
--dart-define ...-
Start sample backends as described in the Starting example app backend services section.
-
Start the example app as described in the Running the example app section.
-
Open Delivery Driver (LMFS) example page and copy the
vehicle ID.
-
Open the LMFS backend Fleet Tracking web console at http://localhost:8091/fleet_tracking.html.
-
Paste the
vehicle IDinto theDelivery Vehicle IDinput in Fleet Tracking web console. -
Start navigation on example page.
-
Observe the vehicle updates on the Fleet Tracking web console.