Implemented save & load method
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -1,10 +1,45 @@
|
||||
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() {
|
||||
/// FIXME Just for Debugging
|
||||
/// Fills the game list with some test data.
|
||||
/*Globals.addGameSession(GameSession(
|
||||
gameTitle: 'Spiel am 27.02.2025',
|
||||
players: ['Clara', 'Tobias', 'Yannik', 'Lena', 'Lekaia'],
|
||||
gameHasPointLimit: true));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: 'Freundschaftsrunde',
|
||||
players: ['Felix', 'Jonas', 'Nils'],
|
||||
gameHasPointLimit: false));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: 'Familienabend',
|
||||
players: ['Mama', 'Papa', 'Lisa'],
|
||||
gameHasPointLimit: true,
|
||||
));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: 'Turnier 1. Runde',
|
||||
players: ['Tim', 'Max', 'Sophie', 'Lena'],
|
||||
gameHasPointLimit: false));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: '2 Namen max length',
|
||||
players: ['Heinrich', 'Johannes'],
|
||||
gameHasPointLimit: true));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: '3 Namen max length',
|
||||
players: ['Benjamin', 'Stefanie', 'Wolfgang'],
|
||||
gameHasPointLimit: false));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: '4 Namen max length',
|
||||
players: ['Leonhard', 'Mathilde', 'Bernhard', 'Gerlinde'],
|
||||
gameHasPointLimit: true));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: '5 Namen max length',
|
||||
players: ['Hartmuth', 'Elisabet', 'Rosalind', 'Theresia', 'Karoline'],
|
||||
gameHasPointLimit: false));
|
||||
*/
|
||||
runApp(const App());
|
||||
}
|
||||
|
||||
@@ -13,13 +48,15 @@ class App extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
LocalStorageService.loadGameSessions();
|
||||
|
||||
return CupertinoApp(
|
||||
theme: CupertinoThemeData(
|
||||
brightness: Brightness.dark,
|
||||
primaryColor: Theme.primaryColor,
|
||||
scaffoldBackgroundColor: Theme.backgroundColor,
|
||||
primaryColor: AppTheme.primaryColor,
|
||||
scaffoldBackgroundColor: AppTheme.backgroundColor,
|
||||
textTheme: CupertinoTextThemeData(
|
||||
primaryColor: Theme.primaryColor,
|
||||
primaryColor: AppTheme.primaryColor,
|
||||
),
|
||||
),
|
||||
debugShowCheckedModeBanner: false,
|
||||
@@ -28,41 +65,7 @@ class App extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// FIXME Just for Debugging
|
||||
/// Fills the game list with some test data.
|
||||
void fillGameList() {
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: 'Spiel am 27.02.2025',
|
||||
players: ['Clara', 'Tobias', 'Yannik', 'Lena', 'Lekaia'],
|
||||
gameHasPointLimit: true));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: 'Freundschaftsrunde',
|
||||
players: ['Felix', 'Jonas', 'Nils'],
|
||||
gameHasPointLimit: false));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: 'Familienabend',
|
||||
players: ['Mama', 'Papa', 'Lisa'],
|
||||
gameHasPointLimit: true,
|
||||
));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: 'Turnier 1. Runde',
|
||||
players: ['Tim', 'Max', 'Sophie', 'Lena'],
|
||||
gameHasPointLimit: false));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: '2 Namen max length',
|
||||
players: ['Heinrich', 'Johannes'],
|
||||
gameHasPointLimit: true));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: '3 Namen max length',
|
||||
players: ['Benjamin', 'Stefanie', 'Wolfgang'],
|
||||
gameHasPointLimit: false));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: '4 Namen max length',
|
||||
players: ['Leonhard', 'Mathilde', 'Bernhard', 'Gerlinde'],
|
||||
gameHasPointLimit: true));
|
||||
Globals.addGameSession(GameSession(
|
||||
gameTitle: '5 Namen max length',
|
||||
players: ['Hartmuth', 'Elisabet', 'Rosalind', 'Theresia', 'Karoline'],
|
||||
gameHasPointLimit: false));
|
||||
dispose() {
|
||||
LocalStorageService.saveGameSessions();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,49 +57,74 @@ class _MainMenuViewState extends State<MainMenuView> {
|
||||
),
|
||||
child: CupertinoPageScaffold(
|
||||
child: SafeArea(
|
||||
child: 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.gameHasPointLimit)}',
|
||||
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: 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),
|
||||
),
|
||||
),
|
||||
onTap: () async {
|
||||
//ignore: unused_local_variable
|
||||
final val = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ActiveGameView(
|
||||
gameSession: Globals.gameList[index]),
|
||||
),
|
||||
);
|
||||
setState(() {});
|
||||
},
|
||||
));
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
: 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.gameHasPointLimit)}',
|
||||
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),
|
||||
],
|
||||
),
|
||||
onTap: () async {
|
||||
//ignore: unused_local_variable
|
||||
final val = await Navigator.push(
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => ActiveGameView(
|
||||
gameSession: Globals.gameList[index]),
|
||||
),
|
||||
);
|
||||
setState(() {});
|
||||
},
|
||||
));
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user