Reworked Settings

This commit is contained in:
Felix Kirchner
2025-05-03 15:50:08 +02:00
parent 639cc4638c
commit 9e44138851

View File

@@ -1,6 +1,7 @@
import 'package:cabo_counter/services/config_service.dart';
import 'package:cabo_counter/services/local_storage_service.dart';
import 'package:cabo_counter/utility/custom_theme.dart';
import 'package:cabo_counter/utility/globals.dart';
import 'package:cabo_counter/widgets/stepper.dart';
import 'package:flutter/cupertino.dart';
import 'package:package_info_plus/package_info_plus.dart';
@@ -14,13 +15,10 @@ class SettingsView extends StatefulWidget {
}
class _SettingsViewState extends State<SettingsView> {
late final int _pointLimit;
late final int _caboPenalty;
bool _isLoading = true;
UniqueKey _stepperKey1 = UniqueKey();
UniqueKey _stepperKey2 = UniqueKey();
@override
void initState() {
_loadSettings();
super.initState();
}
@@ -31,9 +29,7 @@ class _SettingsViewState extends State<SettingsView> {
middle: Text('Einstellungen'),
),
child: SafeArea(
child: _isLoading
? const Center(child: CupertinoActivityIndicator())
: Stack(
child: Stack(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.start,
@@ -51,16 +47,17 @@ class _SettingsViewState extends State<SettingsView> {
child: CupertinoListTile(
padding: EdgeInsets.zero,
title: const Text('Cabo-Strafe'),
subtitle:
const Text('... für falsches Cabo sagen'),
subtitle: const Text('... für falsches Cabo sagen'),
trailing: Stepper(
initialValue: _caboPenalty,
key: _stepperKey1,
initialValue: Globals.caboPenalty,
minValue: 0,
maxValue: 50,
step: 1,
onChanged: (value) {
onChanged: (newCaboPenalty) {
setState(() {
print('Neuer Wert: $value');
ConfigService.setCaboPenalty(newCaboPenalty);
Globals.caboPenalty = newCaboPenalty;
});
},
),
@@ -72,17 +69,33 @@ class _SettingsViewState extends State<SettingsView> {
title: const Text('Punkte-Limit'),
subtitle: const Text('... hier ist Schluss'),
trailing: Stepper(
initialValue: _pointLimit,
key: _stepperKey2,
initialValue: Globals.pointLimit,
minValue: 30,
maxValue: 1000,
step: 10,
onChanged: (value) {
onChanged: (newPointLimit) {
setState(() {
print('Neuer Wert: $value');
ConfigService.setPointLimit(newPointLimit);
Globals.pointLimit = newPointLimit;
});
},
),
)),
Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 0, 0),
child: Center(
heightFactor: 0.9,
child: CupertinoButton(
padding: EdgeInsets.zero,
onPressed: () => setState(() {
ConfigService.resetConfig();
_stepperKey1 = UniqueKey();
_stepperKey2 = UniqueKey();
}),
child: const Text('Standard zurücksetzten'),
),
)),
Padding(
padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
child: Text(
@@ -91,31 +104,35 @@ class _SettingsViewState extends State<SettingsView> {
),
),
Padding(
padding: const EdgeInsets.fromLTRB(30, 10, 10, 0),
padding: const EdgeInsets.only(top: 30),
child: Center(
heightFactor: 1,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CupertinoButton(
color: CustomTheme.primaryColor,
sizeStyle: CupertinoButtonSize.medium,
child: Text(
'Daten exportieren',
style: TextStyle(color: CustomTheme.white),
style:
TextStyle(color: CustomTheme.backgroundColor),
),
onPressed: () async {
final success = await LocalStorageService
.exportJsonFile();
print('Export pressed');
final success =
await LocalStorageService.exportJsonFile();
if (!success && context.mounted) {
showCupertinoDialog(
context: context,
builder: (context) =>
CupertinoAlertDialog(
builder: (context) => CupertinoAlertDialog(
title: const Text('Fehler'),
content: const Text(
'Datei konnte nicht exportiert werden.'),
actions: [
CupertinoDialogAction(
child: const Text('OK'),
onPressed: () =>
Navigator.pop(context),
onPressed: () => Navigator.pop(context),
),
],
),
@@ -123,21 +140,25 @@ class _SettingsViewState extends State<SettingsView> {
}
},
),
const SizedBox(
width: 20,
),
CupertinoButton(
sizeStyle: CupertinoButtonSize.large,
color: CustomTheme.primaryColor,
sizeStyle: CupertinoButtonSize.medium,
child: Text(
'Daten importieren',
style:
TextStyle(color: CustomTheme.white),
TextStyle(color: CustomTheme.backgroundColor),
),
onPressed: () async {
final success = await LocalStorageService
.importJsonFile();
print('Import pressed');
final success =
await LocalStorageService.importJsonFile();
if (!success && context.mounted) {
showCupertinoDialog(
context: context,
builder: (context) =>
CupertinoAlertDialog(
builder: (context) => CupertinoAlertDialog(
title: const Text('Fehler'),
content: const Text(
'Datei konnte nicht importiert werden.'),
@@ -145,8 +166,7 @@ class _SettingsViewState extends State<SettingsView> {
CupertinoDialogAction(
child: const Text('OK'),
onPressed: () =>
Navigator.pop(
context),
Navigator.pop(context),
),
],
));
@@ -154,6 +174,7 @@ class _SettingsViewState extends State<SettingsView> {
}),
],
)),
)
],
),
Positioned(
@@ -206,14 +227,4 @@ class _SettingsViewState extends State<SettingsView> {
Future<PackageInfo> _getPackageInfo() async {
return await PackageInfo.fromPlatform();
}
Future<void> _loadSettings() async {
final pointLimit = await ConfigService.getPointLimit();
final caboPenalty = await ConfigService.getCaboPenalty();
setState(() {
_pointLimit = pointLimit;
_caboPenalty = caboPenalty;
_isLoading = false;
});
}
}