Files
fforte/lib/screens/settings.dart
2025-06-19 17:14:21 +02:00

122 lines
3.9 KiB
Dart

// * Settings screen for the LUPUS app
// * Allows configuration of:
// * - File storage location
// * - GPS tracking interval
// * All settings are persisted using SharedPreferences
import 'package:flutter/material.dart';
import 'package:fforte/l10n/app_localizations.dart';
import 'package:open_file_manager/open_file_manager.dart';
import 'package:shared_preferences/shared_preferences.dart';
// * Widget for the settings screen
class Settings extends StatefulWidget {
const Settings({super.key});
@override
State<Settings> createState() => _SettingsState();
}
// * State class for the settings screen
class _SettingsState extends State<Settings> {
// Default tracking interval in seconds
int _trackingInterval = 60;
@override
void initState() {
super.initState();
_loadSettings(); // Load saved settings on start
}
// * Load settings from SharedPreferences
Future<void> _loadSettings() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
setState(() {
// Load tracking interval or use default (60 seconds)
_trackingInterval = prefs.getInt('trackingInterval') ?? 60;
});
}
// * Save new tracking interval
// * @param value The new interval in seconds
Future<void> _saveTrackingInterval(int value) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setInt('trackingInterval', value);
setState(() {
_trackingInterval = value;
});
}
// * Get configured save directory
// * @return The configured directory or empty string
Future<String> _getSaveDir() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
final String saveDir = prefs.getString('saveDir') ?? "";
return saveDir;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(AppLocalizations.of(context)!.settings),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// * File location section
Text(
AppLocalizations.of(context)!.filelocation,
style: const TextStyle(fontSize: 20),
),
// Display current save directory
FutureBuilder(
future: _getSaveDir(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Text(snapshot.data ?? "");
} else {
return const Text("");
}
}),
// Button to open directory selection
ElevatedButton(
onPressed: () async {
await openFileManager(
androidConfig: AndroidConfig(
folderType: AndroidFolderType.other,
folderPath: await _getSaveDir()));
},
child: Text(AppLocalizations.of(context)!.open)),
const SizedBox(height: 24),
// * Tracking interval section
const Text(
'Tracking Interval (Sekunden)',
style: TextStyle(fontSize: 20),
),
// Slider for interval adjustment
// - Minimum: 10 seconds
// - Maximum: 300 seconds (5 minutes)
// - 29 divisions for precise control
Slider(
value: _trackingInterval.toDouble(),
min: 10,
max: 300,
divisions: 29,
label: _trackingInterval.toString(),
onChanged: (double value) {
_saveTrackingInterval(value.round());
},
),
// Display current interval
Text('Aktuelles Intervall: $_trackingInterval Sekunden'),
],
),
),
);
}
}