diff --git a/docs/sdk/flutter.mdx b/docs/sdk/flutter.mdx
index 2c4373fab..3cc71c09a 100644
--- a/docs/sdk/flutter.mdx
+++ b/docs/sdk/flutter.mdx
@@ -260,7 +260,17 @@ To track the user's location in the foreground, call:
```dart
var res = await Radar.trackOnce();
-// do something with res['status'], res['location'], res['events'], res['user']
+// do something with res['status'], res['location'], res['events'], res['user'] (i.e. check if user is in geofence):
+var geofences = res?['user']?['geofences'];
+if (geofences!= null && geofences.isNotEmpty) {
+ // User is in a geofence, activate on-premise mode
+ setState(() {
+ _displayText = 'In geofence: ${geofences[0]['description']}';
+ });
+} else {
+ // User is not in a geofence
+ print('User is not in any geofence');
+}
```
Learn about platform-specific implementations of this function in the [iOS SDK documentation](/sdk/ios) and [Android SDK documentation](/sdk/android).
@@ -269,7 +279,7 @@ Learn about platform-specific implementations of this function in the [iOS SDK d
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:
+For background tracking, the SDK supports [custom tracking options](https://radar.com/documentation/sdk/tracking) 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.
diff --git a/docs/tutorials/building-an-on-premise-mode.mdx b/docs/tutorials/building-an-on-premise-mode.mdx
index 2ce012805..9600cb52a 100644
--- a/docs/tutorials/building-an-on-premise-mode.mdx
+++ b/docs/tutorials/building-an-on-premise-mode.mdx
@@ -35,7 +35,8 @@ Initialize the SDK with your publishable API key.
{ label: 'Swift', value: 'swift' },
{ label: 'Kotlin', value: 'kotlin' },
{ label: 'Web', value: 'web' },
- { label: 'React Native', value: 'react-native' }
+ { label: 'React Native', value: 'react-native' },
+ { label: 'Flutter', value: 'flutter' }
]}
>
@@ -116,7 +117,61 @@ export default function App() {
```
+
+ ```jsx
+ import 'package:flutter/material.dart';
+ import 'package:flutter_radar/flutter_radar.dart';
+
+ void main() {
+ runApp(MyApp());
+ }
+
+ class MyApp extends StatelessWidget {
+ const MyApp({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return MaterialApp(
+ home: RadarTrackingScreen(),
+ );
+ }
+ }
+
+ class RadarTrackingScreen extends StatefulWidget {
+ const RadarTrackingScreen({super.key});
+
+ @override
+ _RadarTrackingScreenState createState() => _RadarTrackingScreenState();
+ }
+
+ class _RadarTrackingScreenState extends State {
+ @override
+ void initState() {
+ super.initState();
+ _initializeRadar();
+ }
+
+ void _initializeRadar() {
+ Radar.initialize("prj_test_pk_..."); // Replace with your actual Radar publishable key
+ Radar.setUserId('flutter-test-user');
+ Radar.setDescription('Flutter');
+ Radar.setMetadata({'foo': 'bar', 'bax': true, 'qux': 1});
+ Radar.setLogLevel('debug');
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ appBar: AppBar(title: const Text('Radar Tracking')),
+ body: const Center(
+ child: Text('Initialized Radar SDK'),
+ ),
+ );
+ }
+ }
+```
+
### Step 4: Request foreground permissions
@@ -128,7 +183,8 @@ export default function App() {
{ label: 'Swift', value: 'swift' },
{ label: 'Kotlin', value: 'kotlin' },
{ label: 'Web', value: 'web' },
- { label: 'React Native', value: 'react-native' }
+ { label: 'React Native', value: 'react-native' },
+ { label: 'Flutter', value: 'flutter' }
]}
>
@@ -250,6 +306,86 @@ export default function App() {
Learn about platform-specific permissions in the [iOS SDK documentation](/sdk/ios#request-permissions) and [Android SDK documentation](/sdk/android#request-permissions).
+
+
+ ```jsx
+ import 'package:flutter/material.dart';
+ import 'package:flutter_radar/flutter_radar.dart';
+
+ void main() {
+ runApp(MyApp());
+ }
+
+ class MyApp extends StatelessWidget {
+ const MyApp({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return MaterialApp(
+ home: RadarTrackingScreen(),
+ );
+ }
+ }
+
+ class RadarTrackingScreen extends StatefulWidget {
+ const RadarTrackingScreen({super.key});
+
+ @override
+ _RadarTrackingScreenState createState() => _RadarTrackingScreenState();
+ }
+
+ class _RadarTrackingScreenState extends State {
+ String _displayText = 'Initialized Radar SDK';
+
+ @override
+ void initState() {
+ super.initState();
+ _initializeRadar();
+ _requestPermissionsAndTrack();
+ }
+
+ void _initializeRadar() {
+ Radar.initialize("prj_test_pk_...."); // Replace with your actual Radar publishable key
+ Radar.setUserId('flutter-test-user');
+ Radar.setDescription('Flutter');
+ Radar.setMetadata({'foo': 'bar', 'bax': true, 'qux': 1});
+ Radar.setLogLevel('debug');
+ }
+
+ Future _requestPermissionsAndTrack() async {
+ // Initial permission status check
+ var permissionStatus = await Radar.getPermissionsStatus();
+
+ // Check if permissions are not determined
+ if (permissionStatus == 'NOT_DETERMINED') {
+ print('Requesting foreground permissions...');
+ await Radar.requestPermissions(false); // Request foreground permission
+ }
+
+ // Status will be "GRANTED_FOREGROUND" if permissions were granted
+ if (permissionStatus == 'GRANTED_FOREGROUND') {
+ // Activate on-premise experience here
+ } else {
+ // Handle denied permissions
+ print('Location permissions not granted');
+ setState(() {
+ _displayText = 'Permissions denied, tracking is disabled.';
+ });
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ appBar: AppBar(title: const Text('Radar Tracking')),
+ body: const Center(
+ child: Text(_displayText),
+ ),
+ );
+ }
+ }
+```
+
@@ -264,7 +400,8 @@ Call `Radar.trackOnce()` to track the user's location in the foreground. In the
{ label: 'Swift', value: 'swift' },
{ label: 'Kotlin', value: 'kotlin' },
{ label: 'Web', value: 'web' },
- { label: 'React Native', value: 'react-native' }
+ { label: 'React Native', value: 'react-native' },
+ { label: 'Flutter', value: 'flutter' }
]}
>
@@ -428,6 +565,97 @@ export default function App() {
```
+
+
+ ```jsx
+ import 'package:flutter/material.dart';
+ import 'package:flutter_radar/flutter_radar.dart';
+
+ void main() {
+ runApp(MyApp());
+ }
+
+ class MyApp extends StatelessWidget {
+ const MyApp({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return MaterialApp(
+ home: RadarTrackingScreen(),
+ );
+ }
+ }
+
+ class RadarTrackingScreen extends StatefulWidget {
+ const RadarTrackingScreen({super.key});
+
+ @override
+ _RadarTrackingScreenState createState() => _RadarTrackingScreenState();
+ }
+
+ class _RadarTrackingScreenState extends State {
+ String _displayText = 'Initialized Radar SDK';
+
+ @override
+ void initState() {
+ super.initState();
+ _initializeRadar();
+ _requestPermissionsAndTrack();
+ }
+
+ void _initializeRadar() {
+ Radar.initialize("prj_test_pk_..."); // Replace with your actual Radar publishable key
+ Radar.setUserId('flutter-test-user');
+ Radar.setDescription('Flutter');
+ Radar.setMetadata({'foo': 'bar', 'bax': true, 'qux': 1});
+ Radar.setLogLevel('debug');
+ }
+
+ Future _requestPermissionsAndTrack() async {
+ // Initial permission status check
+ var permissionStatus = await Radar.getPermissionsStatus();
+
+ // Check if permissions are not determined
+ if (permissionStatus == 'NOT_DETERMINED') {
+ print('Requesting foreground permissions...');
+ permissionStatus = await Radar.requestPermissions(false); // Request foreground permission
+ }
+
+ if (permissionStatus == 'GRANTED_FOREGROUND') {
+ var res = await Radar.trackOnce();
+
+ // Check if the user is in a geofence to activate on-premise mode
+ var geofences = res?['user']?['geofences'];
+ if (geofences!= null && geofences.isNotEmpty) {
+ // If user is in a geofence, activate on-premise mode
+ setState(() {
+ _displayText = 'In geofence: ${geofences[0]['description']}';
+ });
+ } else {
+ // User is not in a geofence
+ print('User is not in any geofence');
+ }
+ } else {
+ // Handle denied permissions
+ print('Location permissions not granted');
+ setState(() {
+ _displayText = 'Permissions denied, tracking is disabled.';
+ });
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return Scaffold(
+ appBar: AppBar(title: const Text('Radar Tracking')),
+ body: Center(
+ child: Text(_displayText), // Display on-premise mode
+ ),
+ );
+ }
+ }
+ ```
+