geofencing_flutter_plugin 1.3.2-beta.3 geofencing_flutter_plugin: ^1.3.2-beta.3 copied to clipboard
This Flutter plugin extends the functionality offered by the Woosmap Geofencing Mobile SDKs.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:geofencing_flutter_plugin/geofencing_flutter_plugin.dart';
import 'uihelper.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
//initPlatformState();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Woosmap Geofencing',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const GeofencingDemoWidget(),
);
}
}
class GeofencingDemoWidget extends StatefulWidget {
const GeofencingDemoWidget({super.key});
@override
State<GeofencingDemoWidget> createState() => _GeofencingDemoWidget();
}
class _GeofencingDemoWidget extends State<GeofencingDemoWidget> {
final UIHelper uiHelper = UIHelper();
String dropdownValue = 'liveTracking';
String poiRadiusValue = '100';
String fetchRegionId = 'isochrone-plugintest';
String removeRegionId = 'isochrone-plugintest';
String fetchLocationId = '';
String fetchPoiId = '';
String venueId = '';
String beaconRef = '';
late TextEditingController venueIdTextFieldController;
late TextEditingController beaconRefTextFieldController;
var items = [
'liveTracking',
'passiveTracking',
'visitsTracking',
'beaconTracking'
];
@override
void initState() {
super.initState();
venueIdTextFieldController = TextEditingController();
venueIdTextFieldController.addListener(() {
venueId = venueIdTextFieldController.text;
});
beaconRefTextFieldController = TextEditingController();
beaconRefTextFieldController.addListener(() {
beaconRef = beaconRefTextFieldController.text;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Woosmap Geofencing'),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// 'Initialize' Woosmap
const Text(
'Initialize',
style: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: () {
uiHelper.initialize();
},
child: const Text('Initialize'),
),
//Set Woosmap Key
ElevatedButton(
onPressed: () {
uiHelper.setWoosmapApiKey();
},
child: const Text('Set Woosmap Key'),
),
const SizedBox(height: 10),
//Choose tracking profile
const Text(
'Profile',
style: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
ElevatedButton(
onPressed: () {
uiHelper.startTracking(dropdownValue);
},
child: Text('Set Tracking Profile ($dropdownValue)'),
),
const SizedBox(height: 5),
DropdownButton(
isExpanded: true,
value: dropdownValue,
items: items.map((String items) {
return DropdownMenuItem(
value: items,
child: Text(items),
);
}).toList(),
onChanged: (String? newValue) {
dropdownValue = newValue!;
setState(() {
dropdownValue = newValue;
});
},
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: () {
uiHelper.stopTracking();
},
child: const Text('Stop Tracking'),
),
// Custom tracking profiles
const SizedBox(height: 10),
const Text(
'Custom Tracking Profile',
style: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: () {
uiHelper.startCustomTracking(
ProfileSource.local, "localProfile.json");
},
child: const Text('Custom Tracking (local)'),
),
ElevatedButton(
onPressed: () {
uiHelper.startCustomTracking(ProfileSource.external,
"https://raw.githubusercontent.com/lpernelle-wgs/files/master/customProfileLeo.json");
},
child: const Text('Custom Tracking (external)'),
),
// Location permissions
const SizedBox(height: 10),
const Text(
'Location Permissions',
style: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
const SizedBox(height: 5),
ElevatedButton(
onPressed: () {
uiHelper.requestPermissions(true);
},
child: const Text('Request background'),
),
ElevatedButton(
onPressed: () {
uiHelper.requestPermissions(false);
},
child: const Text('Request foreground'),
),
ElevatedButton(
onPressed: () {
uiHelper.getPermissionsStatus();
},
child: const Text('Get Location Permission'),
),
const SizedBox(height: 10),
const Text(
'Bluetooth Permissions',
style: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
const SizedBox(height: 5),
ElevatedButton(
onPressed: () {
uiHelper.requestBLEPermissions();
},
child: const Text('Request BLE Permission'),
),
ElevatedButton(
onPressed: () {
uiHelper.getBLEPermissionsStatus();
},
child: const Text('Get BLE Permission'),
),
const SizedBox(height: 10),
//POI radius
const Text(
'POI Radius',
style: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
const SizedBox(height: 10),
TextField(
onChanged: (String value) {
setState(() {
poiRadiusValue = value;
});
},
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly
],
decoration: const InputDecoration(
hintText: 'Set POI Radius Value',
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Colors.black), //
),
),
),
const SizedBox(height: 5),
ElevatedButton(
onPressed: () {
uiHelper.setPoiRadius(poiRadiusValue);
},
child: const Text('Set POI Radius'),
),
const SizedBox(height: 10),
//Watch location
//POI radius
const Text(
'Watch Location',
style: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
const SizedBox(height: 5),
ElevatedButton(
onPressed: () {
uiHelper.watchLocation();
},
child: const Text('Watch Location'),
),
ElevatedButton(
onPressed: () {
uiHelper.clearLocationWatch();
},
child: const Text('Clear Location Watch'),
),
const SizedBox(height: 10),
//Watch Regions
const Text(
'Watch Region',
style: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
const SizedBox(height: 5),
ElevatedButton(
onPressed: () {
uiHelper.watchRegion();
},
child: const Text('Watch Region'),
),
ElevatedButton(
onPressed: () {
uiHelper.clearRegionWatch();
},
child: const Text('Remove Region Watch'),
),
const SizedBox(height: 10),
//Set SFMC Credentials
const Text(
'SFMC Credentials',
style: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
const SizedBox(height: 5),
ElevatedButton(
onPressed: () {
uiHelper.setSFMCCredentials();
},
child: const Text('Set SFMC Credentials'),
),
const SizedBox(height: 10),
//New Region
const Text(
'New Region',
style: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
const SizedBox(height: 5),
ElevatedButton(
onPressed: () {
GeofenceRegion geofenceRegion = GeofenceRegion(
'circle-plugintest',
51.50998,
-0.1337,
100,
RegionType.circle);
uiHelper.addRegion(geofenceRegion);
},
child: const Text('Add Region (Circle)'),
),
ElevatedButton(
onPressed: () {
GeofenceRegion geofenceRegion = GeofenceRegion(
'isochrone-plugintest',
51.50998,
-0.1337,
100,
RegionType.isochrone);
uiHelper.addRegion(geofenceRegion);
},
child: const Text('Add Region (isochrone)'),
),
const SizedBox(height: 10),
//Retrieve Region
const Text(
'Retrieve Region',
style: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
const SizedBox(height: 5),
TextField(
onChanged: (String value) {
setState(() {
fetchRegionId = value;
});
},
keyboardType: TextInputType.text,
decoration: const InputDecoration(
hintText: 'Region Id',
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Colors.black), //
),
),
),
const SizedBox(height: 5),
ElevatedButton(
onPressed: () {
uiHelper.getRegions(fetchRegionId);
},
child: const Text('Retrieve Single Region'),
),
ElevatedButton(
onPressed: () {
uiHelper.getRegions();
},
child: const Text('Retrieve All Regions'),
),
const SizedBox(height: 10),
//Remove Region
const Text(
'Remove Region',
style: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
const SizedBox(height: 5),
TextField(
onChanged: (String value) {
setState(() {
removeRegionId = value;
});
},
keyboardType: TextInputType.text,
decoration: const InputDecoration(
hintText: 'Remove Region Id',
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Colors.black), //
),
),
),
const SizedBox(height: 5),
ElevatedButton(
onPressed: () {
uiHelper.removeRegions(removeRegionId);
},
child: const Text('Delete Single Region'),
),
ElevatedButton(
onPressed: () {
uiHelper.removeRegions();
},
child: const Text('Delete All Regions'),
),
const SizedBox(height: 10),
//Retrieve Location
const Text(
'Retrieve Location',
style: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
const SizedBox(height: 5),
TextField(
onChanged: (String value) {
setState(() {
fetchLocationId = value;
});
},
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.digitsOnly
],
decoration: const InputDecoration(
hintText: 'Location id',
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Colors.black), //
),
),
),
const SizedBox(height: 5),
ElevatedButton(
onPressed: () {
uiHelper.getLocations(fetchLocationId);
},
child: const Text('Retrieve Single Location'),
),
ElevatedButton(
onPressed: () {
uiHelper.getLocations();
},
child: const Text('Retrieve All Locations'),
),
ElevatedButton(
onPressed: () {
uiHelper.removeLocations();
},
child: const Text('Remove All Locations'),
),
const SizedBox(height: 10),
//Retrieve POI
const Text(
'Retrieve POI',
style: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
const SizedBox(height: 5),
TextField(
onChanged: (String value) {
setState(() {
fetchPoiId = value;
});
},
keyboardType: TextInputType.text,
decoration: const InputDecoration(
hintText: 'POI Id',
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Colors.black), //
),
),
),
const SizedBox(height: 5),
ElevatedButton(
onPressed: () {
uiHelper.getPois(fetchPoiId);
},
child: const Text('Retrieve Single POI'),
),
ElevatedButton(
onPressed: () {
uiHelper.getPois();
},
child: const Text('Retrieve All POIs'),
),
ElevatedButton(
onPressed: () {
uiHelper.refreshPois();
},
child: const Text('Refresh All POIs'),
),
ElevatedButton(
onPressed: () {
uiHelper.removePois();
},
child: const Text('Remove All POIs'),
),
const SizedBox(height: 10),
//Retrieve Indoor POI
const Text(
'Retrieve Indoor Beacons',
style: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
const SizedBox(height: 5),
TextField(
controller: venueIdTextFieldController,
onChanged: (String value) {
setState(() {
venueId = value;
});
},
keyboardType: TextInputType.text,
decoration: const InputDecoration(
hintText: 'Venue ID',
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Colors.black), //
),
),
),
const SizedBox(height: 5),
ElevatedButton(
onPressed: () {
uiHelper.getIndoorBeacons(venueID: venueId);
},
child: const Text('Retrieve Indoor Beacons for venue'),
),
const SizedBox(height: 5),
TextField(
controller: beaconRefTextFieldController,
onChanged: (String value) {
setState(() {
beaconRef = value;
});
},
keyboardType: TextInputType.text,
decoration: const InputDecoration(
hintText: 'Beacon ref',
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Colors.black), //
),
),
),
ElevatedButton(
onPressed: () {
uiHelper.getIndoorBeacons(ref: beaconRef);
},
child: const Text('Retrieve Indoor Beacon by Ref'),
),
ElevatedButton(
onPressed: () {
uiHelper.getIndoorBeacons(
venueIdController: venueIdTextFieldController,
beaconRefController: beaconRefTextFieldController);
},
child: const Text('Retrieve All Indoor Beacons'),
),
ElevatedButton(
onPressed: () {
uiHelper.removeIndoorBeacons();
},
child: const Text('Remove All Indoor Beacons'),
),
const SizedBox(height: 10),
],
),
),
));
}
}