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>
<LaunchAction
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
selectedDebuggerIdentifier = ""
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"

View File

@@ -1,37 +1,12 @@
import 'package:cabo_counter/data/game_session.dart';
import 'package:cabo_counter/utility/globals.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:cabo_counter/views/main_menu_view.dart';
import 'package:flutter/cupertino.dart';
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
/// Fills the game list with some test data.
void fillGameList() {
Globals.addGameSession(GameSession(
/*Globals.addGameSession(GameSession(
gameTitle: 'Spiel am 27.02.2025',
players: ['Clara', 'Tobias', 'Yannik', 'Lena', 'Lekaia'],
gameHasPointLimit: true));
@@ -64,5 +39,33 @@ class App extends StatelessWidget {
gameTitle: '5 Namen max length',
players: ['Hartmuth', 'Elisabet', 'Rosalind', 'Theresia', 'Karoline'],
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/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/information_view.dart';
@@ -14,9 +16,19 @@ class MainMenuView extends StatefulWidget {
}
class _MainMenuViewState extends State<MainMenuView> {
@override
initState() {
super.initState();
LocalStorageService.loadGameSessions().then((_) {
setState(() {});
});
}
@override
Widget build(BuildContext context) {
LocalStorageService.loadGameSessions();
return CupertinoPageScaffold(
resizeToAvoidBottomInset: false,
navigationBar: CupertinoNavigationBar(
leading: IconButton(
onPressed: () {
@@ -45,7 +57,33 @@ class _MainMenuViewState extends State<MainMenuView> {
),
child: CupertinoPageScaffold(
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,
itemBuilder: (context, index) {
final session = Globals.gameList[index];
@@ -66,8 +104,8 @@ class _MainMenuViewState extends State<MainMenuView> {
children: [
Text('${session.roundNumber}'),
const SizedBox(width: 3),
const Icon(
CupertinoIcons.arrow_2_circlepath_circle_fill),
const Icon(CupertinoIcons
.arrow_2_circlepath_circle_fill),
const SizedBox(width: 15),
Text('${session.players.length}'),
const SizedBox(width: 3),
@@ -86,8 +124,7 @@ class _MainMenuViewState extends State<MainMenuView> {
setState(() {});
},
));
},
),
}),
),
),
);

View File

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

View File

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