c4w_location_sdk_flutter 1.0.0
c4w_location_sdk_flutter: ^1.0.0 copied to clipboard
The Cloud4Wi Location SDK (referenced as GeoUniq) abstracts away cross-platform differences between location services, allowing you to add geofencing and location tracking to your apps with just a few [...]
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:c4w_location_sdk_flutter/c4w_location_sdk_flutter.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _statusId = 'Unregistered';
final _c4wLocationSdkFlutterPlugin = C4wLocationSdkFlutter();
@override
void initState() {
super.initState();
_c4wLocationSdkFlutterPlugin.sharedInstance();
_updateStatusId();
}
Future<void> _updateStatusId() async {
String? locationId = await _c4wLocationSdkFlutterPlugin.getLocationId();
setState(() {
_statusId = locationId ?? "No device id";
});
}
Future<void> enableLocationTracking() async {
setState(() {
_statusId = 'start tracking';
});
_c4wLocationSdkFlutterPlugin.enableLocationPermissionConsents();
_c4wLocationSdkFlutterPlugin.startLocationTracking();
try {
String? id =
await _c4wLocationSdkFlutterPlugin.getLocationId();
setState(() {
_statusId = "id: $id";
});
} catch (error) {
setState(() {
_statusId = "Error registration: $error";
});
}
}
void _onButtonPressed() async {
enableLocationTracking();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Column(
children: [
const Text('Location Test App'),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _onButtonPressed,
child: const Text('Enable Tracking'),
),
const SizedBox(height: 30),
Text(_statusId, style: const TextStyle(fontSize: 18)),
],
),
),
),
);
}
}