diff --git a/lib/views/settings_view.dart b/lib/views/settings_view.dart index 90cbd2b..44d3e2e 100644 --- a/lib/views/settings_view.dart +++ b/lib/views/settings_view.dart @@ -1,5 +1,10 @@ +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/widgets/stepper.dart'; import 'package:flutter/cupertino.dart'; import 'package:package_info_plus/package_info_plus.dart'; +import 'package:url_launcher/url_launcher.dart'; class SettingsView extends StatefulWidget { const SettingsView({super.key}); @@ -9,6 +14,18 @@ class SettingsView extends StatefulWidget { } class _SettingsViewState extends State { + final TextEditingController _gameTitleTextController = + TextEditingController(); + late final int _pointLimit; + late final int _caboPenalty; + bool _isLoading = true; + + @override + void initState() { + _loadSettings(); + super.initState(); + } + @override Widget build(BuildContext context) { return CupertinoPageScaffold( @@ -16,50 +33,189 @@ class _SettingsViewState extends State { middle: Text('Einstellungen'), ), child: SafeArea( - child: Stack( - children: [ - const Column( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Center( - child: Icon( - CupertinoIcons.settings, - size: 100, - )), - ], - ), - Positioned( - bottom: 30, - left: 0, - right: 0, - child: 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, - ); - }, - )), - ], - )), + child: _isLoading + ? const Center(child: CupertinoActivityIndicator()) + : 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( + 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, + ), + ), + 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( + title: const Text('Fehler'), + content: const Text( + 'Datei konnte nicht exportiert werden.'), + actions: [ + CupertinoDialogAction( + child: const Text('OK'), + onPressed: () => + 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, 20), + 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, + ); + }, + ) + ], + )), + ], + )), ); } 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; + }); + } }