Implemented save & load method

This commit is contained in:
Felix Kirchner
2025-04-30 17:17:01 +02:00
parent 8fed846eac
commit 11f87bc198
5 changed files with 140 additions and 93 deletions

View File

@@ -52,8 +52,8 @@
</TestAction> </TestAction>
<LaunchAction <LaunchAction
buildConfiguration = "Release" buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
launchStyle = "0" launchStyle = "0"
useCustomWorkingDirectory = "NO" useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO" ignoresPersistentStateOnLaunch = "NO"

View File

@@ -1,37 +1,12 @@
import 'package:cabo_counter/data/game_session.dart'; import 'package:cabo_counter/utility/apptheme.dart';
import 'package:cabo_counter/utility/globals.dart'; import 'package:cabo_counter/utility/local_storage_service.dart';
import 'package:cabo_counter/utility/theme.dart';
import 'package:cabo_counter/views/main_menu_view.dart'; import 'package:cabo_counter/views/main_menu_view.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
void main() { void main() {
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return CupertinoApp(
theme: CupertinoThemeData(
brightness: Brightness.dark,
primaryColor: Theme.primaryColor,
scaffoldBackgroundColor: Theme.backgroundColor,
textTheme: CupertinoTextThemeData(
primaryColor: Theme.primaryColor,
),
),
debugShowCheckedModeBanner: false,
title: 'Cabo Counter',
home: const MainMenuView(),
);
}
/// FIXME Just for Debugging /// FIXME Just for Debugging
/// Fills the game list with some test data. /// Fills the game list with some test data.
void fillGameList() { /*Globals.addGameSession(GameSession(
Globals.addGameSession(GameSession(
gameTitle: 'Spiel am 27.02.2025', gameTitle: 'Spiel am 27.02.2025',
players: ['Clara', 'Tobias', 'Yannik', 'Lena', 'Lekaia'], players: ['Clara', 'Tobias', 'Yannik', 'Lena', 'Lekaia'],
gameHasPointLimit: true)); gameHasPointLimit: true));
@@ -64,5 +39,33 @@ class App extends StatelessWidget {
gameTitle: '5 Namen max length', gameTitle: '5 Namen max length',
players: ['Hartmuth', 'Elisabet', 'Rosalind', 'Theresia', 'Karoline'], players: ['Hartmuth', 'Elisabet', 'Rosalind', 'Theresia', 'Karoline'],
gameHasPointLimit: false)); gameHasPointLimit: false));
*/
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
LocalStorageService.loadGameSessions();
return CupertinoApp(
theme: CupertinoThemeData(
brightness: Brightness.dark,
primaryColor: AppTheme.primaryColor,
scaffoldBackgroundColor: AppTheme.backgroundColor,
textTheme: CupertinoTextThemeData(
primaryColor: AppTheme.primaryColor,
),
),
debugShowCheckedModeBanner: false,
title: 'Cabo Counter',
home: const MainMenuView(),
);
}
dispose() {
LocalStorageService.saveGameSessions();
} }
} }

View File

@@ -1,4 +1,6 @@
import 'package:cabo_counter/utility/apptheme.dart';
import 'package:cabo_counter/utility/globals.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/active_game_view.dart';
import 'package:cabo_counter/views/create_game_view.dart'; import 'package:cabo_counter/views/create_game_view.dart';
import 'package:cabo_counter/views/information_view.dart'; import 'package:cabo_counter/views/information_view.dart';
@@ -14,9 +16,19 @@ class MainMenuView extends StatefulWidget {
} }
class _MainMenuViewState extends State<MainMenuView> { class _MainMenuViewState extends State<MainMenuView> {
@override
initState() {
super.initState();
LocalStorageService.loadGameSessions().then((_) {
setState(() {});
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
LocalStorageService.loadGameSessions();
return CupertinoPageScaffold( return CupertinoPageScaffold(
resizeToAvoidBottomInset: false,
navigationBar: CupertinoNavigationBar( navigationBar: CupertinoNavigationBar(
leading: IconButton( leading: IconButton(
onPressed: () { onPressed: () {
@@ -45,7 +57,33 @@ class _MainMenuViewState extends State<MainMenuView> {
), ),
child: CupertinoPageScaffold( child: CupertinoPageScaffold(
child: SafeArea( child: SafeArea(
child: ListView.builder( 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: AppTheme.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, itemCount: Globals.gameList.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final session = Globals.gameList[index]; final session = Globals.gameList[index];
@@ -66,8 +104,8 @@ class _MainMenuViewState extends State<MainMenuView> {
children: [ children: [
Text('${session.roundNumber}'), Text('${session.roundNumber}'),
const SizedBox(width: 3), const SizedBox(width: 3),
const Icon( const Icon(CupertinoIcons
CupertinoIcons.arrow_2_circlepath_circle_fill), .arrow_2_circlepath_circle_fill),
const SizedBox(width: 15), const SizedBox(width: 15),
Text('${session.players.length}'), Text('${session.players.length}'),
const SizedBox(width: 3), const SizedBox(width: 3),
@@ -86,8 +124,7 @@ class _MainMenuViewState extends State<MainMenuView> {
setState(() {}); setState(() {});
}, },
)); ));
}, }),
),
), ),
), ),
); );

View File

@@ -1,5 +1,6 @@
import 'package:cabo_counter/data/game_session.dart'; import 'package:cabo_counter/data/game_session.dart';
import 'package:cabo_counter/utility/theme.dart'; import 'package:cabo_counter/utility/apptheme.dart';
import 'package:cabo_counter/utility/local_storage_service.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart'; import 'package:flutter_keyboard_visibility/flutter_keyboard_visibility.dart';
@@ -71,7 +72,10 @@ class _RoundViewState extends State<RoundView> {
previousPageTitle: 'Übersicht', previousPageTitle: 'Übersicht',
leading: CupertinoButton( leading: CupertinoButton(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
onPressed: () => Navigator.pop(context, widget.gameSession), onPressed: () => {
LocalStorageService.saveGameSessions(),
Navigator.pop(context, widget.gameSession)
},
child: const Text('Abbrechen'), child: const Text('Abbrechen'),
), ),
), ),
@@ -86,7 +90,7 @@ class _RoundViewState extends State<RoundView> {
children: [ children: [
const SizedBox(height: 40), const SizedBox(height: 40),
Text('Runde ${widget.roundNumber}', Text('Runde ${widget.roundNumber}',
style: Theme.roundTitle), style: AppTheme.roundTitle),
const SizedBox(height: 10), const SizedBox(height: 10),
const Text( const Text(
'Wer hat CABO gesagt?', 'Wer hat CABO gesagt?',
@@ -101,8 +105,8 @@ class _RoundViewState extends State<RoundView> {
child: SizedBox( child: SizedBox(
height: 40, height: 40,
child: CupertinoSegmentedControl<int>( child: CupertinoSegmentedControl<int>(
unselectedColor: Theme.backgroundTintColor, unselectedColor: AppTheme.backgroundTintColor,
selectedColor: Theme.primaryColor, selectedColor: AppTheme.primaryColor,
groupValue: _caboPlayerIndex, groupValue: _caboPlayerIndex,
children: Map.fromEntries(widget.gameSession.players children: Map.fromEntries(widget.gameSession.players
.asMap() .asMap()
@@ -267,7 +271,7 @@ class _RoundViewState extends State<RoundView> {
return Container( return Container(
height: 80, height: 80,
padding: const EdgeInsets.only(bottom: 20), padding: const EdgeInsets.only(bottom: 20),
color: Theme.backgroundTintColor, color: AppTheme.backgroundTintColor,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
@@ -275,6 +279,7 @@ class _RoundViewState extends State<RoundView> {
onPressed: _areRoundInputsValid() onPressed: _areRoundInputsValid()
? () { ? () {
_finishRound(); _finishRound();
LocalStorageService.saveGameSessions();
Navigator.pop(context, widget.gameSession); Navigator.pop(context, widget.gameSession);
} }
: null, : null,
@@ -284,6 +289,7 @@ class _RoundViewState extends State<RoundView> {
onPressed: _areRoundInputsValid() onPressed: _areRoundInputsValid()
? () { ? () {
_finishRound(); _finishRound();
LocalStorageService.saveGameSessions();
if (widget.gameSession.isGameFinished == true) { if (widget.gameSession.isGameFinished == true) {
Navigator.pop(context, widget.gameSession); Navigator.pop(context, widget.gameSession);
} else { } else {

View File

@@ -2,7 +2,7 @@ name: cabo_counter
description: "Mobile app for the card game Cabo" description: "Mobile app for the card game Cabo"
publish_to: 'none' publish_to: 'none'
version: 0.1.3+65 version: 0.1.3+101
environment: environment:
sdk: ^3.5.4 sdk: ^3.5.4
@@ -15,6 +15,7 @@ dependencies:
url_launcher: any url_launcher: any
package_info_plus: any package_info_plus: any
flutter_keyboard_visibility: ^6.0.0 flutter_keyboard_visibility: ^6.0.0
path_provider: ^2.1.1
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: