SPEC modifications
This commit is contained in:
parent
1b7d4e5f78
commit
4598e859f5
6 changed files with 171 additions and 367 deletions
|
|
@ -344,7 +344,7 @@
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
shellPath = /bin/sh;
|
shellPath = /bin/sh;
|
||||||
shellScript = "\n#!/bin/bash\nPATH=\"${PATH}:$FLUTTER_ROOT/bin:${PUB_CACHE}/bin:$HOME/.pub-cache/bin\"\n\nif [ -z \"$PODS_ROOT\" ] || [ ! -d \"$PODS_ROOT/FirebaseCrashlytics\" ]; then\n # Cannot use \"BUILD_DIR%/Build/*\" as per Firebase documentation, it points to \"flutter-project/build/ios/*\" path which doesn't have run script\n DERIVED_DATA_PATH=$(echo \"$BUILD_ROOT\" | sed -E 's|(.*DerivedData/[^/]+).*|\\1|')\n PATH_TO_CRASHLYTICS_UPLOAD_SCRIPT=\"${DERIVED_DATA_PATH}/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run\"\nelse\n PATH_TO_CRASHLYTICS_UPLOAD_SCRIPT=\"$PODS_ROOT/FirebaseCrashlytics/run\"\nfi\n\n# Command to upload symbols script used to upload symbols to Firebase server\nflutterfire upload-crashlytics-symbols --upload-symbols-script-path=\"$PATH_TO_CRASHLYTICS_UPLOAD_SCRIPT\" --platform=ios --apple-project-path=\"${SRCROOT}\" --env-platform-name=\"${PLATFORM_NAME}\" --env-configuration=\"${CONFIGURATION}\" --env-project-dir=\"${PROJECT_DIR}\" --env-built-products-dir=\"${BUILT_PRODUCTS_DIR}\" --env-dwarf-dsym-folder-path=\"${DWARF_DSYM_FOLDER_PATH}\" --env-dwarf-dsym-file-name=\"${DWARF_DSYM_FILE_NAME}\" --env-infoplist-path=\"${INFOPLIST_PATH}\" --default-config=default\n";
|
shellScript = "\n#!/bin/bash\n# Skip Firebase Crashlytics for now\nexit 0\nPATH=\"${PATH}:$FLUTTER_ROOT/bin:${PUB_CACHE}/bin:$HOME/.pub-cache/bin\"\n\nif [ -z \"$PODS_ROOT\" ] || [ ! -d \"$PODS_ROOT/FirebaseCrashlytics\" ]; then\n # Cannot use \"BUILD_DIR%/Build/*\" as per Firebase documentation, it points to \"flutter-project/build/ios/*\" path which doesn't have run script\n DERIVED_DATA_PATH=$(echo \"$BUILD_ROOT\" | sed -E 's|(.*DerivedData/[^/]+).*|\\1|')\n PATH_TO_CRASHLYTICS_UPLOAD_SCRIPT=\"${DERIVED_DATA_PATH}/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run\"\nelse\n PATH_TO_CRASHLYTICS_UPLOAD_SCRIPT=\"$PODS_ROOT/FirebaseCrashlytics/run\"\nfi\n\n# Command to upload symbols script used to upload symbols to Firebase server\nflutterfire upload-crashlytics-symbols --upload-symbols-script-path=\"$PATH_TO_CRASHLYTICS_UPLOAD_SCRIPT\" --platform=ios --apple-project-path=\"${SRCROOT}\" --env-platform-name=\"${PLATFORM_NAME}\" --env-configuration=\"${CONFIGURATION}\" --env-project-dir=\"${PROJECT_DIR}\" --env-built-products-dir=\"${BUILT_PRODUCTS_DIR}\" --env-dwarf-dsym-folder-path=\"${DWARF_DSYM_FOLDER_PATH}\" --env-dwarf-dsym-file-name=\"${DWARF_DSYM_FILE_NAME}\" --env-infoplist-path=\"${INFOPLIST_PATH}\" --default-config=default\n";
|
||||||
};
|
};
|
||||||
9740EEB61CF901F6004384FC /* Run Script */ = {
|
9740EEB61CF901F6004384FC /* Run Script */ = {
|
||||||
isa = PBXShellScriptBuildPhase;
|
isa = PBXShellScriptBuildPhase;
|
||||||
|
|
|
||||||
24
lib/config.dart
Normal file
24
lib/config.dart
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
class AppConfig {
|
||||||
|
AppConfig._();
|
||||||
|
|
||||||
|
/// Traccar server URL
|
||||||
|
static const String serverUrl = 'https://c.track.rs';
|
||||||
|
|
||||||
|
/// Location accuracy: 'highest', 'high', 'medium', or 'low'
|
||||||
|
static const String accuracy = 'highest';
|
||||||
|
|
||||||
|
/// Location update interval in seconds
|
||||||
|
static const int intervalSeconds = 60;
|
||||||
|
|
||||||
|
/// Distance filter in meters (0 = disabled)
|
||||||
|
static const int distanceFilter = 0;
|
||||||
|
|
||||||
|
/// Whether to enable stop detection
|
||||||
|
static const bool stopDetection = false;
|
||||||
|
|
||||||
|
/// Whether to buffer locations when offline
|
||||||
|
static const bool buffer = true;
|
||||||
|
|
||||||
|
/// Fastest location update interval in seconds (Android)
|
||||||
|
static const int fastestIntervalSeconds = 30;
|
||||||
|
}
|
||||||
|
|
@ -1,15 +1,10 @@
|
||||||
import 'package:app_settings/app_settings.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:traccar_client/main.dart';
|
import 'package:traccar_client/main.dart';
|
||||||
import 'package:traccar_client/password_service.dart';
|
|
||||||
import 'package:traccar_client/preferences.dart';
|
import 'package:traccar_client/preferences.dart';
|
||||||
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
|
|
||||||
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;
|
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;
|
||||||
|
|
||||||
import 'l10n/app_localizations.dart';
|
import 'l10n/app_localizations.dart';
|
||||||
import 'status_screen.dart';
|
|
||||||
import 'settings_screen.dart';
|
|
||||||
|
|
||||||
class MainScreen extends StatefulWidget {
|
class MainScreen extends StatefulWidget {
|
||||||
const MainScreen({super.key});
|
const MainScreen({super.key});
|
||||||
|
|
@ -74,144 +69,76 @@ class _MainScreenState extends State<MainScreen> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildTrackingCard() {
|
@override
|
||||||
return Card(
|
Widget build(BuildContext context) {
|
||||||
child: Padding(
|
final deviceId = Preferences.instance.getString(Preferences.id) ?? '';
|
||||||
padding: const EdgeInsets.all(16),
|
return Scaffold(
|
||||||
child: Column(
|
appBar: AppBar(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
title: const Text('Traccar Client'),
|
||||||
children: [
|
),
|
||||||
ListTile(
|
body: Center(
|
||||||
contentPadding: EdgeInsets.zero,
|
child: SingleChildScrollView(
|
||||||
title: Text(AppLocalizations.of(context)!.trackingTitle),
|
padding: const EdgeInsets.all(16.0),
|
||||||
titleTextStyle: Theme.of(context).textTheme.headlineMedium,
|
child: Column(
|
||||||
),
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
ListTile(
|
children: [
|
||||||
contentPadding: EdgeInsets.zero,
|
Card(
|
||||||
title: Text(AppLocalizations.of(context)!.idLabel),
|
child: Padding(
|
||||||
subtitle: Text(Preferences.instance.getString(Preferences.id) ?? ''),
|
padding: const EdgeInsets.all(24),
|
||||||
),
|
child: Column(
|
||||||
SwitchListTile(
|
children: [
|
||||||
contentPadding: EdgeInsets.zero,
|
Text(
|
||||||
title: Text(AppLocalizations.of(context)!.trackingLabel),
|
'Device ID',
|
||||||
value: trackingEnabled,
|
style: Theme.of(context).textTheme.labelLarge,
|
||||||
activeTrackColor: isMoving == false ? Theme.of(context).colorScheme.secondary : null,
|
),
|
||||||
onChanged: (bool value) async {
|
const SizedBox(height: 8),
|
||||||
if (await PasswordService.authenticate(context) && mounted) {
|
SelectableText(
|
||||||
if (value) {
|
deviceId,
|
||||||
try {
|
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
||||||
FirebaseCrashlytics.instance.log('tracking_toggle_start');
|
fontFamily: 'monospace',
|
||||||
await bg.BackgroundGeolocation.start();
|
fontWeight: FontWeight.bold,
|
||||||
if (mounted) {
|
),
|
||||||
_checkBatteryOptimizations(context);
|
),
|
||||||
}
|
],
|
||||||
} on PlatformException catch (error) {
|
),
|
||||||
final providerState = await bg.BackgroundGeolocation.providerState;
|
),
|
||||||
final isPermissionError = providerState.status == bg.ProviderChangeEvent.AUTHORIZATION_STATUS_DENIED ||
|
),
|
||||||
providerState.status == bg.ProviderChangeEvent.AUTHORIZATION_STATUS_RESTRICTED;
|
const SizedBox(height: 16),
|
||||||
|
Card(
|
||||||
|
child: SwitchListTile(
|
||||||
|
title: const Text('Continuous Tracking'),
|
||||||
|
subtitle: Text(
|
||||||
|
trackingEnabled
|
||||||
|
? 'Sending location updates'
|
||||||
|
: 'Location tracking disabled',
|
||||||
|
),
|
||||||
|
value: trackingEnabled,
|
||||||
|
activeTrackColor: isMoving == false
|
||||||
|
? Theme.of(context).colorScheme.error
|
||||||
|
: null,
|
||||||
|
onChanged: (bool value) async {
|
||||||
|
if (value) {
|
||||||
|
try {
|
||||||
|
await bg.BackgroundGeolocation.start();
|
||||||
|
if (mounted) {
|
||||||
|
_checkBatteryOptimizations(context);
|
||||||
|
}
|
||||||
|
} on PlatformException catch (error) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
messengerKey.currentState?.showSnackBar(
|
messengerKey.currentState?.showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(error.message ?? error.code),
|
content: Text(error.message ?? error.code),
|
||||||
duration: const Duration(seconds: 4),
|
|
||||||
action: isPermissionError
|
|
||||||
? SnackBarAction(
|
|
||||||
label: AppLocalizations.of(context)!.settingsTitle,
|
|
||||||
onPressed: () => AppSettings.openAppSettings(
|
|
||||||
type: AppSettingsType.settings,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: null,
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
FirebaseCrashlytics.instance.log('tracking_toggle_stop');
|
bg.BackgroundGeolocation.stop();
|
||||||
bg.BackgroundGeolocation.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
OverflowBar(
|
|
||||||
spacing: 8,
|
|
||||||
children: [
|
|
||||||
FilledButton.tonal(
|
|
||||||
onPressed: () async {
|
|
||||||
try {
|
|
||||||
await bg.BackgroundGeolocation.getCurrentPosition(samples: 1, persist: true, extras: {'manual': true});
|
|
||||||
} on PlatformException catch (error) {
|
|
||||||
messengerKey.currentState?.showSnackBar(SnackBar(content: Text(error.message ?? error.code)));
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: Text(AppLocalizations.of(context)!.locationButton),
|
|
||||||
),
|
),
|
||||||
FilledButton.tonal(
|
),
|
||||||
onPressed: () {
|
],
|
||||||
Navigator.push(context, MaterialPageRoute(builder: (_) => const StatusScreen()));
|
),
|
||||||
},
|
|
||||||
child: Text(AppLocalizations.of(context)!.statusButton),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildSettingsCard() {
|
|
||||||
return Card(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(16),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
ListTile(
|
|
||||||
contentPadding: EdgeInsets.zero,
|
|
||||||
title: Text(AppLocalizations.of(context)!.settingsTitle),
|
|
||||||
titleTextStyle: Theme.of(context).textTheme.headlineMedium,
|
|
||||||
),
|
|
||||||
ListTile(
|
|
||||||
contentPadding: EdgeInsets.zero,
|
|
||||||
title: Text(AppLocalizations.of(context)!.urlLabel),
|
|
||||||
subtitle: Text(Preferences.instance.getString(Preferences.url) ?? ''),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
OverflowBar(
|
|
||||||
spacing: 8,
|
|
||||||
children: [
|
|
||||||
FilledButton.tonal(
|
|
||||||
onPressed: () async {
|
|
||||||
if (await PasswordService.authenticate(context) && mounted) {
|
|
||||||
await Navigator.push(context, MaterialPageRoute(builder: (_) => const SettingsScreen()));
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: Text(AppLocalizations.of(context)!.settingsButton),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
title: Text('Traccar Client'),
|
|
||||||
),
|
|
||||||
body: SingleChildScrollView(
|
|
||||||
padding: const EdgeInsets.all(16.0),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
_buildTrackingCard(),
|
|
||||||
const SizedBox(height: 16),
|
|
||||||
_buildSettingsCard(),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import 'package:flutter_background_geolocation/flutter_background_geolocation.da
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:shared_preferences_android/shared_preferences_android.dart';
|
import 'package:shared_preferences_android/shared_preferences_android.dart';
|
||||||
|
|
||||||
|
import 'config.dart';
|
||||||
|
|
||||||
class Preferences {
|
class Preferences {
|
||||||
static Future<void>? _initFuture;
|
static Future<void>? _initFuture;
|
||||||
static late SharedPreferencesWithCache instance;
|
static late SharedPreferencesWithCache instance;
|
||||||
|
|
@ -47,37 +49,35 @@ class Preferences {
|
||||||
);
|
);
|
||||||
if (instance.getString(id) == null) {
|
if (instance.getString(id) == null) {
|
||||||
await instance.setString(id, (Random().nextInt(90000000) + 10000000).toString());
|
await instance.setString(id, (Random().nextInt(90000000) + 10000000).toString());
|
||||||
await instance.setString(url, 'http://demo.traccar.org:5055');
|
|
||||||
await instance.setString(accuracy, 'medium');
|
|
||||||
await instance.setInt(interval, 300);
|
|
||||||
await instance.setInt(distance, 75);
|
|
||||||
await instance.setBool(buffer, true);
|
|
||||||
await instance.setBool(stopDetection, true);
|
|
||||||
await instance.setInt(fastestInterval, 30);
|
|
||||||
}
|
}
|
||||||
|
await instance.setString(url, AppConfig.serverUrl);
|
||||||
|
await instance.setString(accuracy, AppConfig.accuracy);
|
||||||
|
await instance.setInt(interval, AppConfig.intervalSeconds);
|
||||||
|
await instance.setInt(distance, AppConfig.distanceFilter);
|
||||||
|
await instance.setBool(buffer, instance.getBool(buffer) ?? AppConfig.buffer);
|
||||||
|
await instance.setBool(stopDetection, AppConfig.stopDetection);
|
||||||
|
await instance.setInt(fastestInterval, instance.getInt(fastestInterval) ?? AppConfig.fastestIntervalSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bg.Config geolocationConfig() {
|
static bg.Config geolocationConfig() {
|
||||||
final isHighestAccuracy = instance.getString(accuracy) == 'highest';
|
final isHighestAccuracy = AppConfig.accuracy == 'highest';
|
||||||
final locationUpdateInterval = (instance.getInt(interval) ?? 0) * 1000;
|
final locationUpdateInterval = isHighestAccuracy ? 0 : AppConfig.intervalSeconds * 1000;
|
||||||
final fastestLocationUpdateInterval = (instance.getInt(fastestInterval) ?? 30) * 1000;
|
final fastestLocationUpdateInterval = isHighestAccuracy ? 0 : AppConfig.fastestIntervalSeconds * 1000;
|
||||||
final heartbeatInterval = instance.getInt(heartbeat) ?? 0;
|
final heartbeatInterval = instance.getInt(heartbeat) ?? 0;
|
||||||
return bg.Config(
|
return bg.Config(
|
||||||
isMoving: true,
|
isMoving: true,
|
||||||
geolocation: bg.GeoConfig(
|
geolocation: bg.GeoConfig(
|
||||||
desiredAccuracy: switch (instance.getString(accuracy)) {
|
desiredAccuracy: switch (AppConfig.accuracy) {
|
||||||
'highest' => Platform.isIOS ? bg.DesiredAccuracy.navigation : bg.DesiredAccuracy.high,
|
'highest' => Platform.isIOS ? bg.DesiredAccuracy.navigation : bg.DesiredAccuracy.high,
|
||||||
'high' => bg.DesiredAccuracy.high,
|
'high' => bg.DesiredAccuracy.high,
|
||||||
'low' => bg.DesiredAccuracy.low,
|
'low' => bg.DesiredAccuracy.low,
|
||||||
_ => bg.DesiredAccuracy.medium,
|
_ => bg.DesiredAccuracy.medium,
|
||||||
},
|
},
|
||||||
distanceFilter: isHighestAccuracy ? 0 : instance.getInt(distance)?.toDouble(),
|
distanceFilter: AppConfig.distanceFilter.toDouble(),
|
||||||
locationUpdateInterval: Platform.isAndroid
|
locationUpdateInterval: Platform.isAndroid ? locationUpdateInterval : null,
|
||||||
? (isHighestAccuracy ? 0 : (locationUpdateInterval > 0 ? locationUpdateInterval : null))
|
fastestLocationUpdateInterval: Platform.isAndroid ? fastestLocationUpdateInterval : null,
|
||||||
: null,
|
|
||||||
fastestLocationUpdateInterval: Platform.isAndroid ? (isHighestAccuracy ? 0 : fastestLocationUpdateInterval) : null,
|
|
||||||
disableElasticity: true,
|
disableElasticity: true,
|
||||||
pausesLocationUpdatesAutomatically: Platform.isIOS ? !(isHighestAccuracy || instance.getBool(stopDetection) == false) : null,
|
pausesLocationUpdatesAutomatically: Platform.isIOS ? false : null,
|
||||||
showsBackgroundLocationIndicator: Platform.isIOS ? false : null,
|
showsBackgroundLocationIndicator: Platform.isIOS ? false : null,
|
||||||
),
|
),
|
||||||
app: bg.AppConfig(
|
app: bg.AppConfig(
|
||||||
|
|
@ -102,7 +102,7 @@ class Preferences {
|
||||||
),
|
),
|
||||||
http: bg.HttpConfig(
|
http: bg.HttpConfig(
|
||||||
autoSync: false,
|
autoSync: false,
|
||||||
url: _formatUrl(instance.getString(url)),
|
url: _formatUrl(AppConfig.serverUrl),
|
||||||
params: {
|
params: {
|
||||||
'device_id': instance.getString(id),
|
'device_id': instance.getString(id),
|
||||||
},
|
},
|
||||||
|
|
@ -112,10 +112,10 @@ class Preferences {
|
||||||
logMaxDays: 1,
|
logMaxDays: 1,
|
||||||
),
|
),
|
||||||
activity: bg.ActivityConfig(
|
activity: bg.ActivityConfig(
|
||||||
disableStopDetection: instance.getBool(stopDetection) == false,
|
disableStopDetection: !AppConfig.stopDetection,
|
||||||
),
|
),
|
||||||
persistence: bg.PersistenceConfig(
|
persistence: bg.PersistenceConfig(
|
||||||
maxRecordsToPersist: instance.getBool(buffer) != false ? -1 : 1,
|
maxRecordsToPersist: AppConfig.buffer ? -1 : 1,
|
||||||
locationTemplate: _locationTemplate(),
|
locationTemplate: _locationTemplate(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,9 @@
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;
|
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;
|
||||||
import 'package:traccar_client/main.dart';
|
import 'package:traccar_client/main.dart';
|
||||||
import 'package:traccar_client/password_service.dart';
|
|
||||||
import 'package:traccar_client/qr_code_screen.dart';
|
|
||||||
import 'package:wakelock_partial_android/wakelock_partial_android.dart';
|
|
||||||
|
|
||||||
import 'l10n/app_localizations.dart';
|
import 'config.dart';
|
||||||
import 'preferences.dart';
|
import 'preferences.dart';
|
||||||
|
|
||||||
class SettingsScreen extends StatefulWidget {
|
class SettingsScreen extends StatefulWidget {
|
||||||
|
|
@ -19,223 +14,81 @@ class SettingsScreen extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SettingsScreenState extends State<SettingsScreen> {
|
class _SettingsScreenState extends State<SettingsScreen> {
|
||||||
bool advanced = false;
|
bool trackingEnabled = false;
|
||||||
|
|
||||||
String _getAccuracyLabel(String? key) {
|
@override
|
||||||
return switch (key) {
|
void initState() {
|
||||||
'highest' => AppLocalizations.of(context)!.highestAccuracyLabel,
|
super.initState();
|
||||||
'high' => AppLocalizations.of(context)!.highAccuracyLabel,
|
_initState();
|
||||||
'low' => AppLocalizations.of(context)!.lowAccuracyLabel,
|
|
||||||
_ => AppLocalizations.of(context)!.mediumAccuracyLabel,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _editSetting(String title, String key, bool isInt) async {
|
void _initState() async {
|
||||||
final initialValue = isInt
|
final state = await bg.BackgroundGeolocation.state;
|
||||||
? Preferences.instance.getInt(key)?.toString() ?? '0'
|
setState(() {
|
||||||
: Preferences.instance.getString(key) ?? '';
|
trackingEnabled = state.enabled;
|
||||||
|
});
|
||||||
final controller = TextEditingController(text: initialValue);
|
bg.BackgroundGeolocation.onEnabledChange((bool enabled) {
|
||||||
final errorMessage = AppLocalizations.of(context)!.invalidValue;
|
setState(() {
|
||||||
|
trackingEnabled = enabled;
|
||||||
final result = await showDialog<String>(
|
});
|
||||||
context: context,
|
});
|
||||||
builder: (context) => AlertDialog(
|
|
||||||
scrollable: true,
|
|
||||||
title: Text(title),
|
|
||||||
content: TextField(
|
|
||||||
controller: controller,
|
|
||||||
keyboardType: isInt ? TextInputType.number : TextInputType.text,
|
|
||||||
inputFormatters: isInt ? [FilteringTextInputFormatter.digitsOnly] : [],
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
child: Text(AppLocalizations.of(context)!.cancelButton),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(context, controller.text),
|
|
||||||
child: Text(AppLocalizations.of(context)!.saveButton),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result != null && result.isNotEmpty) {
|
|
||||||
if (key == Preferences.url) {
|
|
||||||
final uri = Uri.tryParse(result);
|
|
||||||
if (uri == null || uri.host.isEmpty || !(uri.scheme == 'http' || uri.scheme == 'https')) {
|
|
||||||
messengerKey.currentState?.showSnackBar(SnackBar(content: Text(errorMessage)));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isInt) {
|
|
||||||
int? intValue = int.tryParse(result);
|
|
||||||
if (intValue != null) {
|
|
||||||
if (key == Preferences.heartbeat && intValue > 0 && intValue < 60) {
|
|
||||||
intValue = 60; // minimum heartbeat is 60 seconds
|
|
||||||
}
|
|
||||||
await Preferences.instance.setInt(key, intValue);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
await Preferences.instance.setString(key, result);
|
|
||||||
}
|
|
||||||
await bg.BackgroundGeolocation.setConfig(Preferences.geolocationConfig());
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _changePassword() async {
|
|
||||||
final controller = TextEditingController();
|
|
||||||
final result = await showDialog<bool>(
|
|
||||||
context: context,
|
|
||||||
builder: (context) => AlertDialog(
|
|
||||||
scrollable: true,
|
|
||||||
content: TextField(
|
|
||||||
controller: controller,
|
|
||||||
decoration: InputDecoration(labelText: AppLocalizations.of(context)!.passwordLabel),
|
|
||||||
obscureText: true,
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(context, false),
|
|
||||||
child: Text(AppLocalizations.of(context)!.cancelButton),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(context, true),
|
|
||||||
child: Text(AppLocalizations.of(context)!.saveButton),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (result == true) {
|
|
||||||
await PasswordService.setPassword(controller.text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildListTile(String title, String key, bool isInt) {
|
|
||||||
String? value;
|
|
||||||
if (isInt) {
|
|
||||||
final intValue = Preferences.instance.getInt(key);
|
|
||||||
if (intValue != null && intValue > 0) {
|
|
||||||
value = intValue.toString();
|
|
||||||
} else {
|
|
||||||
value = AppLocalizations.of(context)!.disabledValue;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
value = Preferences.instance.getString(key);
|
|
||||||
}
|
|
||||||
return ListTile(
|
|
||||||
title: Text(title),
|
|
||||||
subtitle: Text(value ?? ''),
|
|
||||||
onTap: () => _editSetting(title, key, isInt),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildAccuracyListTile() {
|
|
||||||
final accuracyOptions = ['highest', 'high', 'medium', 'low'];
|
|
||||||
return ListTile(
|
|
||||||
title: Text(AppLocalizations.of(context)!.accuracyLabel),
|
|
||||||
subtitle: Text(_getAccuracyLabel(Preferences.instance.getString(Preferences.accuracy))),
|
|
||||||
onTap: () async {
|
|
||||||
final selectedAccuracy = await showDialog<String>(
|
|
||||||
context: context,
|
|
||||||
builder: (context) => SimpleDialog(
|
|
||||||
title: Text(AppLocalizations.of(context)!.accuracyLabel),
|
|
||||||
children: accuracyOptions.map((option) => SimpleDialogOption(
|
|
||||||
child: Text(_getAccuracyLabel(option)),
|
|
||||||
onPressed: () => Navigator.pop(context, option),
|
|
||||||
)).toList(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (selectedAccuracy != null) {
|
|
||||||
await Preferences.instance.setString(Preferences.accuracy, selectedAccuracy);
|
|
||||||
await bg.BackgroundGeolocation.setConfig(Preferences.geolocationConfig());
|
|
||||||
setState(() {});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final isHighestAccuracy = Preferences.instance.getString(Preferences.accuracy) == 'highest';
|
|
||||||
final distance = Preferences.instance.getInt(Preferences.distance);
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(AppLocalizations.of(context)!.settingsTitle),
|
title: const Text('Settings'),
|
||||||
actions: [
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.qr_code_scanner),
|
|
||||||
onPressed: () async {
|
|
||||||
await Navigator.push(context, MaterialPageRoute(builder: (_) => const QrCodeScreen()));
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
body: ListView(
|
body: ListView(
|
||||||
children: [
|
children: [
|
||||||
_buildListTile(AppLocalizations.of(context)!.idLabel, Preferences.id, false),
|
ListTile(
|
||||||
_buildListTile(AppLocalizations.of(context)!.urlLabel, Preferences.url, false),
|
title: const Text('Device ID'),
|
||||||
_buildAccuracyListTile(),
|
subtitle: Text(Preferences.instance.getString(Preferences.id) ?? ''),
|
||||||
_buildListTile(AppLocalizations.of(context)!.distanceLabel, Preferences.distance, true),
|
enabled: false,
|
||||||
if (isHighestAccuracy || Platform.isAndroid && distance == 0)
|
),
|
||||||
_buildListTile(AppLocalizations.of(context)!.intervalLabel, Preferences.interval, true),
|
|
||||||
if (isHighestAccuracy)
|
|
||||||
_buildListTile(AppLocalizations.of(context)!.angleLabel, Preferences.angle, true),
|
|
||||||
_buildListTile(AppLocalizations.of(context)!.heartbeatLabel, Preferences.heartbeat, true),
|
|
||||||
SwitchListTile(
|
SwitchListTile(
|
||||||
title: Text(AppLocalizations.of(context)!.advancedLabel),
|
title: const Text('Continuous Tracking'),
|
||||||
value: advanced,
|
value: trackingEnabled,
|
||||||
onChanged: (value) {
|
onChanged: (bool value) async {
|
||||||
setState(() => advanced = value);
|
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();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (advanced)
|
ListTile(
|
||||||
_buildListTile(AppLocalizations.of(context)!.fastestIntervalLabel, Preferences.fastestInterval, true),
|
title: const Text('Server'),
|
||||||
if (advanced)
|
subtitle: Text(AppConfig.serverUrl),
|
||||||
SwitchListTile(
|
enabled: false,
|
||||||
title: Text(AppLocalizations.of(context)!.bufferLabel),
|
),
|
||||||
value: Preferences.instance.getBool(Preferences.buffer) ?? true,
|
ListTile(
|
||||||
onChanged: (value) async {
|
title: const Text('Location Accuracy'),
|
||||||
await Preferences.instance.setBool(Preferences.buffer, value);
|
subtitle: Text(AppConfig.accuracy),
|
||||||
await bg.BackgroundGeolocation.setConfig(Preferences.geolocationConfig());
|
enabled: false,
|
||||||
setState(() {});
|
),
|
||||||
},
|
ListTile(
|
||||||
),
|
title: const Text('Distance'),
|
||||||
if (advanced && Platform.isAndroid)
|
subtitle: Text(AppConfig.distanceFilter == 0 ? 'Disabled' : '${AppConfig.distanceFilter}'),
|
||||||
SwitchListTile(
|
enabled: false,
|
||||||
title: Text(AppLocalizations.of(context)!.wakelockLabel),
|
),
|
||||||
value: Preferences.instance.getBool(Preferences.wakelock) ?? false,
|
ListTile(
|
||||||
onChanged: (value) async {
|
title: const Text('Interval'),
|
||||||
await Preferences.instance.setBool(Preferences.wakelock, value);
|
subtitle: Text('${AppConfig.intervalSeconds} seconds'),
|
||||||
if (value) {
|
enabled: false,
|
||||||
final state = await bg.BackgroundGeolocation.state;
|
),
|
||||||
if (state.isMoving == true) {
|
ListTile(
|
||||||
WakelockPartialAndroid.acquire();
|
title: const Text('Stop Detection'),
|
||||||
}
|
subtitle: Text(AppConfig.stopDetection ? 'Enabled' : 'Disabled'),
|
||||||
} else {
|
enabled: false,
|
||||||
WakelockPartialAndroid.release();
|
),
|
||||||
}
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
if (advanced)
|
|
||||||
SwitchListTile(
|
|
||||||
title: Text(AppLocalizations.of(context)!.stopDetectionLabel),
|
|
||||||
value: Preferences.instance.getBool(Preferences.stopDetection) ?? true,
|
|
||||||
onChanged: (value) async {
|
|
||||||
await Preferences.instance.setBool(Preferences.stopDetection, value);
|
|
||||||
await bg.BackgroundGeolocation.setConfig(Preferences.geolocationConfig());
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
if (advanced)
|
|
||||||
ListTile(
|
|
||||||
title: Text(AppLocalizations.of(context)!.passwordLabel),
|
|
||||||
onTap: _changePassword,
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -441,10 +441,10 @@ packages:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: matcher
|
name: matcher
|
||||||
sha256: "12956d0ad8390bbcc63ca2e1469c0619946ccb52809807067a7020d57e647aa6"
|
sha256: dc0b7dc7651697ea4ff3e69ef44b0407ea32c487a39fff6a4004fa585e901861
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.12.18"
|
version: "0.12.19"
|
||||||
material_color_utilities:
|
material_color_utilities:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -726,10 +726,10 @@ packages:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: test_api
|
name: test_api
|
||||||
sha256: "93167629bfc610f71560ab9312acdda4959de4df6fac7492c89ff0d3886f6636"
|
sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.7.9"
|
version: "0.7.10"
|
||||||
typed_data:
|
typed_data:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue