Radar is location data infrastructure. You can use Radar SDKs and APIs to add location context to your apps with just a few lines of code.
See the Radar overview documentation here.
This is a community developed plugin.
Flutter support:
- iOS
- Android
- User management
- Geofencing
- Geo APIs (geocoding, distance, autocomplete)
- Search (geofences, points and places)
- Location tracking and context (foreground and background)
- Trip tracking
- Create a Location Permissed Foreground Service (Android)
- Mock tracking
- Accept/reject events
radar_flutter_plugin is compatible only from version 16 of Android SDK so you should change this in android/app/build.gradle if needed:
Android {
defaultConfig {
minSdkVersion: 16
We need to add the permission to request location:
In the android/app/src/main/AndroidManifest.xml let’s add:
<manifest>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
...
</manifest>
The Plugin also includes the ability to start a foreground service associated with the main activity. This allows for continued location updates when the app is backgrounded but the while in use location permission is granted and also allows for mitigation of [background location limits] (https://developer.android.com/training/location/background#limit-updates).
If there is planned use of this functionality, in the the android/app/src/main/AndroidManifest.xml let's add:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
dependencies {
...
implementation 'io.radar:sdk:3.0.9'
}
Open the MainApplication
class for your project. Note: MainApplication
is not created by default through flutter create <Project>
, so you may need to create it.
Add code to extend the Flutter Application class
(FlutterApplication
) that imports and initializes Reader SDK:
package <YOUR_PACKAGE_NAME>;
import io.flutter.app.FlutterApplication;
import io.flutter.view.FlutterMain;
import io.radar.sdk.Radar;
public class MainApplication extends FlutterApplication {
@Override
public void onCreate() {
super.onCreate();
Radar.initialize(this,"<yourRadarPublishableKey>");
FlutterMain.startInitialization(this);
}
}
If you create MainApplication
class in above step, update AndroidManifest.xml
in your project:
<application
<!-- use custom "MainApplication" class instead of "io.flutter.app.FlutterApplication" -->
android:name=".MainApplication"
... />
</application>
In MainActivity
you might need the following engine registration:
public class MainActivity extends FlutterActivity {
@Override
public void configureFlutterEngine(FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
In the ios/Runner/Info.plist let’s add the following replacing the usage description strings content as appropriate:
<dict>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Your iOS 11 and higher background location usage description goes here. e.g., "This app uses your location in the background to recommend places nearby."</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Your iOS 10 and lower background location usage description goes here. e.g., "This app uses your location in the background to recommend places nearby."</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your foreground location usage description goes here. e.g., "This app uses your location in the foreground to recommend places nearby."</string>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>location</string>
</array>
...
</dict>
For location permissions on iOS see more at: https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services
The Radar SDK supports iOS 10 and higher. You might need to adjust the following if not already done:
- Adjust the
MinimumOSVersion
inios/Flutter/Flutter.framework/AppFrameworkInfo.plist
:
<key>MinimumOSVersion</key>
<string>10.0</string>
- Adjust your Podfile to define a global platform (
platform :ios, '10.0'
) and comment out use frameworks (# use_frameworks!
) if needed.
objective-c example:
#import <RadarSDK/RadarSDK.h>
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[Radar initializeWithPublishableKey:@"yourRadarPublishableKey"];
[GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch.
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end
swift example:
import RadarSDK
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
Radar.initialize(publishableKey: "<yourRadarPublishableKey>")
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
To use this plugin, add radar_flutter_plugin
as a dependency in your pubspec.yaml file. For example:
dependencies:
radar_flutter_plugin: ^0.0.1
See here for example applications of Radar and the example app for relevant functions.