Implemented full SettingsView
This commit is contained in:
@@ -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:flutter/cupertino.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
class SettingsView extends StatefulWidget {
|
class SettingsView extends StatefulWidget {
|
||||||
const SettingsView({super.key});
|
const SettingsView({super.key});
|
||||||
@@ -9,6 +14,18 @@ class SettingsView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SettingsViewState extends State<SettingsView> {
|
class _SettingsViewState extends State<SettingsView> {
|
||||||
|
final TextEditingController _gameTitleTextController =
|
||||||
|
TextEditingController();
|
||||||
|
late final int _pointLimit;
|
||||||
|
late final int _caboPenalty;
|
||||||
|
bool _isLoading = true;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
_loadSettings();
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return CupertinoPageScaffold(
|
return CupertinoPageScaffold(
|
||||||
@@ -16,16 +33,128 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
middle: Text('Einstellungen'),
|
middle: Text('Einstellungen'),
|
||||||
),
|
),
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
child: Stack(
|
child: _isLoading
|
||||||
|
? const Center(child: CupertinoActivityIndicator())
|
||||||
|
: Stack(
|
||||||
children: [
|
children: [
|
||||||
const Column(
|
Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Center(
|
Padding(
|
||||||
child: Icon(
|
padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
|
||||||
CupertinoIcons.settings,
|
child: Text(
|
||||||
size: 100,
|
'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),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
],
|
||||||
)),
|
)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -33,7 +162,22 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
bottom: 30,
|
bottom: 30,
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
child: FutureBuilder<PackageInfo>(
|
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<PackageInfo>(
|
||||||
future: _getPackageInfo(),
|
future: _getPackageInfo(),
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
@@ -53,6 +197,8 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
)),
|
)),
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
@@ -62,4 +208,14 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
Future<PackageInfo> _getPackageInfo() async {
|
Future<PackageInfo> _getPackageInfo() async {
|
||||||
return await PackageInfo.fromPlatform();
|
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;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user