2025-05-05 08:02:02 -07:00
|
|
|
import 'package:flutter/material.dart';
|
2025-05-07 07:46:20 -07:00
|
|
|
import 'package:flutter/services.dart';
|
2025-05-07 17:42:07 -07:00
|
|
|
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;
|
2025-06-30 23:00:08 -07:00
|
|
|
import 'package:traccar_client/main.dart';
|
2025-05-07 07:46:20 -07:00
|
|
|
|
2026-03-06 12:32:44 +11:00
|
|
|
import 'config.dart';
|
2025-05-07 07:46:20 -07:00
|
|
|
import 'preferences.dart';
|
2025-05-05 08:02:02 -07:00
|
|
|
|
|
|
|
|
class SettingsScreen extends StatefulWidget {
|
2025-05-07 18:27:11 -07:00
|
|
|
const SettingsScreen({super.key});
|
2025-05-05 08:02:02 -07:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<SettingsScreen> createState() => _SettingsScreenState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _SettingsScreenState extends State<SettingsScreen> {
|
2026-03-06 12:32:44 +11:00
|
|
|
bool trackingEnabled = false;
|
2025-05-07 07:46:20 -07:00
|
|
|
|
2026-03-06 12:32:44 +11:00
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
_initState();
|
2025-06-28 14:57:56 -07:00
|
|
|
}
|
|
|
|
|
|
2026-03-06 12:32:44 +11:00
|
|
|
void _initState() async {
|
|
|
|
|
final state = await bg.BackgroundGeolocation.state;
|
|
|
|
|
setState(() {
|
|
|
|
|
trackingEnabled = state.enabled;
|
|
|
|
|
});
|
|
|
|
|
bg.BackgroundGeolocation.onEnabledChange((bool enabled) {
|
|
|
|
|
setState(() {
|
|
|
|
|
trackingEnabled = enabled;
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-05-08 21:51:43 -07:00
|
|
|
}
|
|
|
|
|
|
2025-05-05 08:02:02 -07:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
2025-06-23 21:32:17 -07:00
|
|
|
appBar: AppBar(
|
2026-03-06 12:32:44 +11:00
|
|
|
title: const Text('Settings'),
|
2025-06-23 21:32:17 -07:00
|
|
|
),
|
2025-05-05 08:02:02 -07:00
|
|
|
body: ListView(
|
|
|
|
|
children: [
|
2026-03-06 12:32:44 +11:00
|
|
|
ListTile(
|
|
|
|
|
title: const Text('Device ID'),
|
|
|
|
|
subtitle: Text(Preferences.instance.getString(Preferences.id) ?? ''),
|
|
|
|
|
enabled: false,
|
|
|
|
|
),
|
2025-05-05 08:02:02 -07:00
|
|
|
SwitchListTile(
|
2026-03-06 12:32:44 +11:00
|
|
|
title: const Text('Continuous Tracking'),
|
|
|
|
|
value: trackingEnabled,
|
|
|
|
|
onChanged: (bool value) async {
|
|
|
|
|
if (value) {
|
|
|
|
|
try {
|
|
|
|
|
await bg.BackgroundGeolocation.start();
|
|
|
|
|
} on PlatformException catch (error) {
|
|
|
|
|
messengerKey.currentState?.showSnackBar(
|
|
|
|
|
SnackBar(content: Text(error.message ?? error.code)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
bg.BackgroundGeolocation.stop();
|
|
|
|
|
}
|
2025-05-05 08:02:02 -07:00
|
|
|
},
|
|
|
|
|
),
|
2026-03-06 12:32:44 +11:00
|
|
|
ListTile(
|
|
|
|
|
title: const Text('Server'),
|
|
|
|
|
subtitle: Text(AppConfig.serverUrl),
|
|
|
|
|
enabled: false,
|
|
|
|
|
),
|
|
|
|
|
ListTile(
|
|
|
|
|
title: const Text('Location Accuracy'),
|
|
|
|
|
subtitle: Text(AppConfig.accuracy),
|
|
|
|
|
enabled: false,
|
|
|
|
|
),
|
|
|
|
|
ListTile(
|
|
|
|
|
title: const Text('Distance'),
|
|
|
|
|
subtitle: Text(AppConfig.distanceFilter == 0 ? 'Disabled' : '${AppConfig.distanceFilter}'),
|
|
|
|
|
enabled: false,
|
|
|
|
|
),
|
|
|
|
|
ListTile(
|
|
|
|
|
title: const Text('Interval'),
|
|
|
|
|
subtitle: Text('${AppConfig.intervalSeconds} seconds'),
|
|
|
|
|
enabled: false,
|
|
|
|
|
),
|
|
|
|
|
ListTile(
|
|
|
|
|
title: const Text('Stop Detection'),
|
|
|
|
|
subtitle: Text(AppConfig.stopDetection ? 'Enabled' : 'Disabled'),
|
|
|
|
|
enabled: false,
|
|
|
|
|
),
|
2025-05-05 08:02:02 -07:00
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|