SPEC modifications
This commit is contained in:
parent
1b7d4e5f78
commit
4598e859f5
6 changed files with 171 additions and 367 deletions
|
|
@ -1,15 +1,10 @@
|
|||
import 'package:app_settings/app_settings.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:traccar_client/main.dart';
|
||||
import 'package:traccar_client/password_service.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 'l10n/app_localizations.dart';
|
||||
import 'status_screen.dart';
|
||||
import 'settings_screen.dart';
|
||||
|
||||
class MainScreen extends StatefulWidget {
|
||||
const MainScreen({super.key});
|
||||
|
|
@ -74,144 +69,76 @@ class _MainScreenState extends State<MainScreen> {
|
|||
}
|
||||
}
|
||||
|
||||
Widget _buildTrackingCard() {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(AppLocalizations.of(context)!.trackingTitle),
|
||||
titleTextStyle: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(AppLocalizations.of(context)!.idLabel),
|
||||
subtitle: Text(Preferences.instance.getString(Preferences.id) ?? ''),
|
||||
),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(AppLocalizations.of(context)!.trackingLabel),
|
||||
value: trackingEnabled,
|
||||
activeTrackColor: isMoving == false ? Theme.of(context).colorScheme.secondary : null,
|
||||
onChanged: (bool value) async {
|
||||
if (await PasswordService.authenticate(context) && mounted) {
|
||||
if (value) {
|
||||
try {
|
||||
FirebaseCrashlytics.instance.log('tracking_toggle_start');
|
||||
await bg.BackgroundGeolocation.start();
|
||||
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;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final deviceId = Preferences.instance.getString(Preferences.id) ?? '';
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Traccar Client'),
|
||||
),
|
||||
body: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
'Device ID',
|
||||
style: Theme.of(context).textTheme.labelLarge,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SelectableText(
|
||||
deviceId,
|
||||
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
|
||||
fontFamily: 'monospace',
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
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;
|
||||
messengerKey.currentState?.showSnackBar(
|
||||
SnackBar(
|
||||
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 {
|
||||
FirebaseCrashlytics.instance.log('tracking_toggle_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)));
|
||||
}
|
||||
} else {
|
||||
bg.BackgroundGeolocation.stop();
|
||||
}
|
||||
},
|
||||
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(),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue