flutter_radar package on pub.dev here.
Install
Add the package to yourpubspec.yaml file:
iOS
Change to theios/ directory. In the Podfile, add platform :ios, '10.0' or higher to your target.
On iOS, you must add location usage descriptions and background modes to your Info.plist. Initialize the SDK in application:didFinishLaunchingWithOptions: in AppDelegate.m or AppDelegate.swift, passing in your Radar publishable API key.
Android
On Android, add the Radar Android SDK to thedependencies section of your Android app’s build.gradle file. Ensure the Android SDK version matches the version of your Radar Flutter package.
When upgrading the SDK, ensure the Android SDK version is updated to match the plugin’s pinned version. For details on the latest SDK releases, see the releases page on GitHub.
onCreate() in MainApplication.java, passing in your Radar publishable API key. If your Flutter Android app is in Kotlin, add a Application.kt file and reference this as the application name in your Android manifest.
29 or higher, Radar also requires the ACCESS_BACKGROUND_LOCATION permission. You must add the ACCESS_BACKGROUND_LOCATION permission to your manifest manually:
Integrate
Import module
First, import the package:Initialize
When your app starts, initialize the SDK with your publishable key. Use yourTest Publishable key for testing and non-production environments. Use your Live Publishable key for production environments.
Identify user
To identify the user when logged in, call:userId is a stable unique ID for the user.
To set an optional dictionary of custom metadata for the user, call:
metadata is a map with up to 16 keys and values of type string, boolean, or number.
Finally, to set an optional description for the user, displayed in the dashboard, call:
description is a string.
You only need to call these functions once, as these settings will be persisted across app sessions.
Learn about platform-specific implementations of these functions in the iOS SDK documentation and Android SDK documentation.
Request permissions
Before tracking the user’s location, the user must have granted location permissions for the app. To determine the whether user has granted location permissions for the app, call:status will be a string, one of:
GRANTED_FOREGROUNDGRANTED_BACKGROUNDDENIEDNOT_DETERMINED
background is a boolean indicating whether to request background location permissions or foreground location permissions.
Learn about platform-specific permissions in the iOS SDK documentation and Android SDK documentation.
Foreground tracking
Once you have initialized the SDK and the user has granted permissions, you can track the user’s location. To track the user’s location in the foreground, call:Background tracking
On iOS and Android, once you have initialized the SDK and the user has granted permissions, you can start tracking the user’s location in the background. For background tracking, the SDK supports custom tracking options as well as three presets:EFFICIENT: A low frequency of location updates and lowest battery usage. On Android, avoids Android vitals bad behavior thresholds.RESPONSIVE: A medium frequency of location updates and low battery usage. Suitable for most consumer use cases.CONTINUOUS: A high frequency of location updates and higher battery usage. Suitable for on-demand use cases (e.g., delivery tracking) and some consumer use cases (e.g., order ahead, “mall mode”).
Mock tracking
On iOS and Android, you can simulate a sequence of location updates for testing. For example, to simulate a sequence of 10 location updates every 3 seconds by car from anorigin to a destination, we can call: