From 9e44138851900d5b6b7d1e3f31d30777b47b05cb Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Sat, 3 May 2025 15:50:08 +0200 Subject: [PATCH] Reworked Settings --- lib/views/settings_view.dart | 347 ++++++++++++++++++----------------- 1 file changed, 179 insertions(+), 168 deletions(-) diff --git a/lib/views/settings_view.dart b/lib/views/settings_view.dart index 002bdae..f1230d5 100644 --- a/lib/views/settings_view.dart +++ b/lib/views/settings_view.dart @@ -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 { - late final int _pointLimit; - late final int _caboPenalty; - bool _isLoading = true; - + UniqueKey _stepperKey1 = UniqueKey(); + UniqueKey _stepperKey2 = UniqueKey(); @override void initState() { - _loadSettings(); super.initState(); } @@ -31,86 +29,139 @@ class _SettingsViewState extends State { middle: Text('Einstellungen'), ), child: SafeArea( - child: _isLoading - ? const Center(child: CupertinoActivityIndicator()) - : Stack( - children: [ - Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, + child: Stack( + children: [ + Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.fromLTRB(10, 10, 0, 0), + child: Text( + 'Punkte', + style: CustomTheme.createGameTitle, + ), + ), + Padding( + padding: const EdgeInsets.fromLTRB(15, 10, 10, 0), + child: CupertinoListTile( + padding: EdgeInsets.zero, + title: const Text('Cabo-Strafe'), + subtitle: const Text('... für falsches Cabo sagen'), + trailing: Stepper( + key: _stepperKey1, + initialValue: Globals.caboPenalty, + minValue: 0, + maxValue: 50, + step: 1, + onChanged: (newCaboPenalty) { + setState(() { + ConfigService.setCaboPenalty(newCaboPenalty); + Globals.caboPenalty = newCaboPenalty; + }); + }, + ), + )), + Padding( + padding: const EdgeInsets.fromLTRB(15, 10, 10, 0), + child: CupertinoListTile( + padding: EdgeInsets.zero, + title: const Text('Punkte-Limit'), + subtitle: const Text('... hier ist Schluss'), + trailing: Stepper( + key: _stepperKey2, + initialValue: Globals.pointLimit, + minValue: 30, + maxValue: 1000, + step: 10, + onChanged: (newPointLimit) { + setState(() { + 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( + 'Spieldaten', + style: CustomTheme.createGameTitle, + ), + ), + Padding( + padding: const EdgeInsets.only(top: 30), + child: Center( + heightFactor: 1, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, children: [ - Padding( - padding: const EdgeInsets.fromLTRB(10, 10, 0, 0), + CupertinoButton( + color: CustomTheme.primaryColor, + sizeStyle: CupertinoButtonSize.medium, child: Text( - 'Punkte', - style: CustomTheme.createGameTitle, + 'Daten exportieren', + style: + TextStyle(color: CustomTheme.backgroundColor), ), + onPressed: () async { + print('Export pressed'); + final success = + await LocalStorageService.exportJsonFile(); + if (!success && context.mounted) { + showCupertinoDialog( + context: context, + 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), + ), + ], + ), + ); + } + }, ), - Padding( - padding: const EdgeInsets.fromLTRB(15, 10, 10, 0), - child: CupertinoListTile( - padding: EdgeInsets.zero, - title: const Text('Cabo-Strafe'), - subtitle: - const Text('... für falsches Cabo sagen'), - trailing: Stepper( - initialValue: _caboPenalty, - minValue: 0, - maxValue: 50, - step: 1, - onChanged: (value) { - setState(() { - print('Neuer Wert: $value'); - }); - }, - ), - )), - Padding( - padding: const EdgeInsets.fromLTRB(15, 10, 10, 0), - child: CupertinoListTile( - padding: EdgeInsets.zero, - title: const Text('Punkte-Limit'), - subtitle: const Text('... hier ist Schluss'), - trailing: Stepper( - initialValue: _pointLimit, - minValue: 30, - maxValue: 1000, - step: 10, - onChanged: (value) { - setState(() { - print('Neuer Wert: $value'); - }); - }, - ), - )), - Padding( - padding: const EdgeInsets.fromLTRB(10, 10, 0, 0), - child: Text( - 'Spieldaten', - style: CustomTheme.createGameTitle, - ), + const SizedBox( + width: 20, ), - Padding( - padding: const EdgeInsets.fromLTRB(30, 10, 10, 0), - child: Row( - children: [ - CupertinoButton( - sizeStyle: CupertinoButtonSize.medium, - child: Text( - 'Daten exportieren', - style: TextStyle(color: CustomTheme.white), - ), - onPressed: () async { - final success = await LocalStorageService - .exportJsonFile(); - if (!success && context.mounted) { - showCupertinoDialog( - context: context, - builder: (context) => - CupertinoAlertDialog( + CupertinoButton( + color: CustomTheme.primaryColor, + sizeStyle: CupertinoButtonSize.medium, + child: Text( + 'Daten importieren', + style: + TextStyle(color: CustomTheme.backgroundColor), + ), + onPressed: () async { + print('Import pressed'); + final success = + await LocalStorageService.importJsonFile(); + if (!success && context.mounted) { + showCupertinoDialog( + context: context, + builder: (context) => CupertinoAlertDialog( title: const Text('Fehler'), content: const Text( - 'Datei konnte nicht exportiert werden.'), + 'Datei konnte nicht importiert werden.'), actions: [ CupertinoDialogAction( child: const Text('OK'), @@ -118,102 +169,62 @@ class _SettingsViewState extends State { Navigator.pop(context), ), ], - ), - ); - } - }, - ), - CupertinoButton( - sizeStyle: CupertinoButtonSize.large, - child: Text( - 'Daten importieren', - style: - TextStyle(color: CustomTheme.white), - ), - onPressed: () async { - final success = await LocalStorageService - .importJsonFile(); - if (!success && context.mounted) { - showCupertinoDialog( - context: context, - builder: (context) => - CupertinoAlertDialog( - title: const Text('Fehler'), - content: const Text( - 'Datei konnte nicht importiert werden.'), - actions: [ - CupertinoDialogAction( - child: const Text('OK'), - onPressed: () => - Navigator.pop( - context), - ), - ], - )); - } - }), - ], - )), + )); + } + }), ], + )), + ) + ], + ), + Positioned( + bottom: 30, + left: 0, + right: 0, + child: Column( + children: [ + const Center( + child: Text('Fehler gefunden?'), + ), + Padding( + padding: const EdgeInsets.fromLTRB(0, 0, 0, 30), + child: Center( + child: CupertinoButton( + onPressed: () => launchUrl(Uri.parse( + 'https://github.com/flixcoo/Cabo-Counter/issues')), + child: const Text('Issue erstellen'), + ), ), - Positioned( - bottom: 30, - left: 0, - right: 0, - child: Column( - children: [ - const Center( - child: Text('Fehler gefunden?'), - ), - Padding( - padding: const EdgeInsets.fromLTRB(0, 0, 0, 30), - child: Center( - child: CupertinoButton( - onPressed: () => launchUrl(Uri.parse( - 'https://github.com/flixcoo/Cabo-Counter/issues')), - child: const Text('Issue erstellen'), - ), - ), - ), - FutureBuilder( - future: _getPackageInfo(), - builder: (context, snapshot) { - if (snapshot.hasData) { - return Text( - 'Alpha ${snapshot.data!.version} ' - '(Build ${snapshot.data!.buildNumber})', - textAlign: TextAlign.center, - ); - } else if (snapshot.hasError) { - return const Text( - 'App-Version -.-.- (Build -)', - textAlign: TextAlign.center, - ); - } - return const Text( - 'Lade Version...', - textAlign: TextAlign.center, - ); - }, - ) - ], - )), - ], - )), + ), + FutureBuilder( + future: _getPackageInfo(), + builder: (context, snapshot) { + if (snapshot.hasData) { + return Text( + 'Alpha ${snapshot.data!.version} ' + '(Build ${snapshot.data!.buildNumber})', + textAlign: TextAlign.center, + ); + } else if (snapshot.hasError) { + return const Text( + 'App-Version -.-.- (Build -)', + textAlign: TextAlign.center, + ); + } + return const Text( + 'Lade Version...', + textAlign: TextAlign.center, + ); + }, + ) + ], + )), + ], + )), ); } Future _getPackageInfo() async { return await PackageInfo.fromPlatform(); } - - Future _loadSettings() async { - final pointLimit = await ConfigService.getPointLimit(); - final caboPenalty = await ConfigService.getCaboPenalty(); - setState(() { - _pointLimit = pointLimit; - _caboPenalty = caboPenalty; - _isLoading = false; - }); - } }