Merge branch 'develop' into feature/18-json-validation

# Conflicts:
#	pubspec.yaml
This commit is contained in:
Felix Kirchner
2025-05-03 16:18:27 +02:00
15 changed files with 475 additions and 234 deletions

View File

@@ -28,7 +28,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
child: Text(
'Spieler:innen',
style: CustomTheme.createGameTitle,
style: CustomTheme.rowTitle,
),
),
ListView.builder(
@@ -61,7 +61,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
child: Text(
'Runden',
style: CustomTheme.createGameTitle,
style: CustomTheme.rowTitle,
),
),
ListView.builder(

View File

@@ -1,7 +1,7 @@
import 'package:cabo_counter/data/game_session.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/utility/local_storage_service.dart';
import 'package:cabo_counter/views/active_game_view.dart';
import 'package:cabo_counter/views/mode_selection_view.dart';
import 'package:flutter/cupertino.dart';
@@ -44,11 +44,11 @@ class _CreateGameState extends State<CreateGame> {
padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
child: Text(
'Spiel',
style: CustomTheme.createGameTitle,
style: CustomTheme.rowTitle,
),
),
Padding(
padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
padding: const EdgeInsets.fromLTRB(15, 10, 10, 0),
child: CupertinoTextField(
decoration: const BoxDecoration(),
maxLength: 16,
@@ -60,7 +60,7 @@ class _CreateGameState extends State<CreateGame> {
),
// Spielmodus-Auswahl mit Chevron
Padding(
padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
padding: const EdgeInsets.fromLTRB(15, 10, 10, 0),
child: CupertinoTextField(
decoration: const BoxDecoration(),
readOnly: true,
@@ -77,15 +77,15 @@ class _CreateGameState extends State<CreateGame> {
],
),
onTap: () async {
// Öffne das Modus-Auswahlmenü
final selected = await Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => const ModeSelectionMenu(),
builder: (context) => ModeSelectionMenu(
pointLimit: Globals.pointLimit,
),
),
);
// Aktualisiere den ausgewählten Modus
if (selected != null) {
setState(() {
selectedMode = selected;
@@ -98,7 +98,7 @@ class _CreateGameState extends State<CreateGame> {
padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
child: Text(
'Spieler:innen',
style: CustomTheme.createGameTitle,
style: CustomTheme.rowTitle,
),
),
Expanded(
@@ -282,17 +282,24 @@ class _CreateGameState extends State<CreateGame> {
players.add(controller.text);
}
GameSession gameSession = GameSession(
createdAt: DateTime.now(),
gameTitle: _gameTitleTextController.text,
players: players,
pointLimit: Globals.pointLimit,
caboPenalty: Globals.caboPenalty,
isPointsLimitEnabled: selectedMode!,
);
Globals.addGameSession(gameSession);
LocalStorageService.saveGameSessions();
Navigator.pushReplacement(
context,
CupertinoPageRoute(
builder: (context) =>
ActiveGameView(gameSession: gameSession)));
if (context.mounted) {
Navigator.pushReplacement(
context,
CupertinoPageRoute(
builder: (context) =>
ActiveGameView(gameSession: gameSession)));
} else {
print('Context is not mounted');
}
},
),
),

View File

@@ -1,4 +1,3 @@
import 'package:cabo_counter/utility/local_storage_service.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
@@ -30,7 +29,7 @@ class InformationView extends StatelessWidget {
),
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
const EdgeInsets.symmetric(horizontal: 20, vertical: 30),
child: SizedBox(
height: 200,
child: Image.asset('assets/cabo-counter-logo_rounded.png'),
@@ -51,7 +50,7 @@ class InformationView extends StatelessWidget {
softWrap: true,
)),
const SizedBox(
height: 15,
height: 30,
),
const Text(
'\u00A9 Felix Kirchner',
@@ -74,53 +73,6 @@ class InformationView extends StatelessWidget {
icon: const Icon(FontAwesomeIcons.github)),
],
),
const SizedBox(
height: 10,
),
CupertinoButton(
sizeStyle: CupertinoButtonSize.medium,
child: const Text('Spieldaten exportieren'),
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.medium,
child: const Text('Spieldaten importieren'),
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),
),
],
));
}
}),
],
)));
}

View File

@@ -1,6 +1,6 @@
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/utility/local_storage_service.dart';
import 'package:cabo_counter/views/active_game_view.dart';
import 'package:cabo_counter/views/create_game_view.dart';
import 'package:cabo_counter/views/settings_view.dart';
@@ -16,17 +16,23 @@ class MainMenuView extends StatefulWidget {
}
class _MainMenuViewState extends State<MainMenuView> {
bool _isLoading = true;
@override
initState() {
super.initState();
LocalStorageService.loadGameSessions().then((_) {
setState(() {});
setState(() {
_isLoading = false;
});
});
}
@override
Widget build(BuildContext context) {
print('MainMenuView build');
LocalStorageService.loadGameSessions();
return CupertinoPageScaffold(
resizeToAvoidBottomInset: false,
navigationBar: CupertinoNavigationBar(
@@ -57,74 +63,76 @@ class _MainMenuViewState extends State<MainMenuView> {
),
child: CupertinoPageScaffold(
child: SafeArea(
child: Globals.gameList.isEmpty
? Column(
mainAxisAlignment:
MainAxisAlignment.center, // Oben ausrichten
children: [
const SizedBox(height: 30), // Abstand von oben
Center(
child: GestureDetector(
onTap: () => setState(() {}),
child: Icon(
CupertinoIcons.plus,
size: 60,
color: CustomTheme.primaryColor,
),
)),
const SizedBox(height: 10), // Abstand von oben
const Padding(
padding: EdgeInsets.symmetric(horizontal: 70),
child: Text(
'Ganz schön leer hier...\nFüge über den Button oben rechts eine neue Runde hinzu.',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 16),
),
),
],
)
: ListView.builder(
itemCount: Globals.gameList.length,
itemBuilder: (context, index) {
final session = Globals.gameList[index];
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: CupertinoListTile(
title: Text(session.gameTitle),
subtitle: session.isGameFinished == true
? Text(
'\u{1F947} ${session.winner}',
style: const TextStyle(fontSize: 14),
)
: Text(
'Modus: ${_translateGameMode(session.isPointsLimitEnabled)}',
style: const TextStyle(fontSize: 14),
),
trailing: Row(
children: [
Text('${session.roundNumber}'),
const SizedBox(width: 3),
const Icon(CupertinoIcons
.arrow_2_circlepath_circle_fill),
const SizedBox(width: 15),
Text('${session.players.length}'),
const SizedBox(width: 3),
const Icon(CupertinoIcons.person_2_fill),
],
child: _isLoading
? const Center(child: CupertinoActivityIndicator())
: Globals.gameList.isEmpty
? Column(
mainAxisAlignment:
MainAxisAlignment.center, // Oben ausrichten
children: [
const SizedBox(height: 30), // Abstand von oben
Center(
child: GestureDetector(
onTap: () => setState(() {}),
child: Icon(
CupertinoIcons.plus,
size: 60,
color: CustomTheme.primaryColor,
),
onTap: () async {
//ignore: unused_local_variable
final val = await Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => ActiveGameView(
gameSession: Globals.gameList[index]),
)),
const SizedBox(height: 10), // Abstand von oben
const Padding(
padding: EdgeInsets.symmetric(horizontal: 70),
child: Text(
'Ganz schön leer hier...\nFüge über den Button oben rechts eine neue Runde hinzu.',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 16),
),
),
],
)
: ListView.builder(
itemCount: Globals.gameList.length,
itemBuilder: (context, index) {
final session = Globals.gameList[index];
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: CupertinoListTile(
title: Text(session.gameTitle),
subtitle: session.isGameFinished == true
? Text(
'\u{1F947} ${session.winner}',
style: const TextStyle(fontSize: 14),
)
: Text(
'Modus: ${_translateGameMode(session.isPointsLimitEnabled)}',
style: const TextStyle(fontSize: 14),
),
trailing: Row(
children: [
Text('${session.roundNumber}'),
const SizedBox(width: 3),
const Icon(CupertinoIcons
.arrow_2_circlepath_circle_fill),
const SizedBox(width: 15),
Text('${session.players.length}'),
const SizedBox(width: 3),
const Icon(CupertinoIcons.person_2_fill),
],
),
);
setState(() {});
},
));
}),
onTap: () async {
//ignore: unused_local_variable
final val = await Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => ActiveGameView(
gameSession: Globals.gameList[index]),
),
);
setState(() {});
},
));
}),
),
),
);

View File

@@ -2,7 +2,8 @@ import 'package:cabo_counter/utility/custom_theme.dart';
import 'package:flutter/cupertino.dart';
class ModeSelectionMenu extends StatelessWidget {
const ModeSelectionMenu({super.key});
final int pointLimit;
const ModeSelectionMenu({super.key, required this.pointLimit});
@override
Widget build(BuildContext context) {
@@ -15,9 +16,9 @@ class ModeSelectionMenu extends StatelessWidget {
Padding(
padding: const EdgeInsets.fromLTRB(0, 16, 0, 0),
child: CupertinoListTile(
title: Text('101 Punkte', style: CustomTheme.modeTitle),
subtitle: const Text(
'Es wird solange gespielt, bis einer Spieler mehr als 100 Punkte erreicht',
title: Text('$pointLimit Punkte', style: CustomTheme.modeTitle),
subtitle: Text(
'Es wird solange gespielt, bis einer Spieler mehr als $pointLimit Punkte erreicht',
style: CustomTheme.modeDescription,
maxLines: 3,
),

View File

@@ -1,6 +1,6 @@
import 'package:cabo_counter/data/game_session.dart';
import 'package:cabo_counter/services/local_storage_service.dart';
import 'package:cabo_counter/utility/custom_theme.dart';
import 'package:cabo_counter/utility/local_storage_service.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';

View File

@@ -1,5 +1,11 @@
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';
import 'package:url_launcher/url_launcher.dart';
class SettingsView extends StatefulWidget {
const SettingsView({super.key});
@@ -9,6 +15,13 @@ class SettingsView extends StatefulWidget {
}
class _SettingsViewState extends State<SettingsView> {
UniqueKey _stepperKey1 = UniqueKey();
UniqueKey _stepperKey2 = UniqueKey();
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
@@ -18,41 +31,193 @@ class _SettingsViewState extends State<SettingsView> {
child: SafeArea(
child: Stack(
children: [
const Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Icon(
CupertinoIcons.settings,
size: 100,
)),
Padding(
padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
child: Text(
'Punkte',
style: CustomTheme.rowTitle,
),
),
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.rowTitle,
),
),
Padding(
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.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),
),
],
),
);
}
},
),
const SizedBox(
width: 20,
),
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 importiert werden.'),
actions: [
CupertinoDialogAction(
child: const Text('OK'),
onPressed: () =>
Navigator.pop(context),
),
],
));
}
}),
],
)),
)
],
),
Positioned(
bottom: 30,
left: 0,
right: 0,
child: FutureBuilder<PackageInfo>(
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: 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<PackageInfo>(
future: _getPackageInfo(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Text(
'${Globals.appDevPhase} ${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,
);
},
)
],
)),
],
)),