Merge branch 'develop' into feature/18-json-validation
# Conflicts: # pubspec.yaml
This commit is contained in:
@@ -11,20 +11,25 @@ import 'package:cabo_counter/data/round.dart';
|
|||||||
/// [isGameFinished] is a boolean indicating if the game has ended yet.
|
/// [isGameFinished] is a boolean indicating if the game has ended yet.
|
||||||
/// [winner] is the name of the player who won the game.
|
/// [winner] is the name of the player who won the game.
|
||||||
class GameSession {
|
class GameSession {
|
||||||
final DateTime createdAt = DateTime.now();
|
final DateTime createdAt;
|
||||||
final String gameTitle;
|
final String gameTitle;
|
||||||
final bool isPointsLimitEnabled;
|
|
||||||
final List<String> players;
|
final List<String> players;
|
||||||
late List<int> playerScores;
|
final int pointLimit;
|
||||||
List<Round> roundList = [];
|
final int caboPenalty;
|
||||||
int roundNumber = 1;
|
final bool isPointsLimitEnabled;
|
||||||
bool isGameFinished = false;
|
bool isGameFinished = false;
|
||||||
String winner = '';
|
String winner = '';
|
||||||
|
int roundNumber = 1;
|
||||||
|
late List<int> playerScores;
|
||||||
|
List<Round> roundList = [];
|
||||||
|
|
||||||
GameSession({
|
GameSession({
|
||||||
|
required this.createdAt,
|
||||||
required this.gameTitle,
|
required this.gameTitle,
|
||||||
required this.isPointsLimitEnabled,
|
|
||||||
required this.players,
|
required this.players,
|
||||||
|
required this.pointLimit,
|
||||||
|
required this.caboPenalty,
|
||||||
|
required this.isPointsLimitEnabled,
|
||||||
}) {
|
}) {
|
||||||
playerScores = List.filled(players.length, 0);
|
playerScores = List.filled(players.length, 0);
|
||||||
}
|
}
|
||||||
@@ -32,33 +37,37 @@ class GameSession {
|
|||||||
@override
|
@override
|
||||||
toString() {
|
toString() {
|
||||||
return ('GameSession: [createdAt: $createdAt, gameTitle: $gameTitle, '
|
return ('GameSession: [createdAt: $createdAt, gameTitle: $gameTitle, '
|
||||||
'isPointsLimitEnabled: $isPointsLimitEnabled, players: $players, '
|
'isPointsLimitEnabled: $isPointsLimitEnabled, pointLimit: $pointLimit, caboPenalty: $caboPenalty,'
|
||||||
'playerScores: $playerScores, roundList: $roundList, '
|
' players: $players, playerScores: $playerScores, roundList: $roundList, winner: $winner]');
|
||||||
'roundNumber: $roundNumber, isGameFinished: $isGameFinished, '
|
|
||||||
'winner: $winner]');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts the GameSession object to a JSON map.
|
/// Converts the GameSession object to a JSON map.
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
|
'createdAt': createdAt.toIso8601String(),
|
||||||
'gameTitle': gameTitle,
|
'gameTitle': gameTitle,
|
||||||
'gameHasPointLimit': isPointsLimitEnabled,
|
|
||||||
'players': players,
|
'players': players,
|
||||||
'playerScores': playerScores,
|
'pointLimit': pointLimit,
|
||||||
'roundNumber': roundNumber,
|
'caboPenalty': caboPenalty,
|
||||||
|
'isPointsLimitEnabled': isPointsLimitEnabled,
|
||||||
'isGameFinished': isGameFinished,
|
'isGameFinished': isGameFinished,
|
||||||
'winner': winner,
|
'winner': winner,
|
||||||
|
'roundNumber': roundNumber,
|
||||||
|
'playerScores': playerScores,
|
||||||
'roundList': roundList.map((e) => e.toJson()).toList()
|
'roundList': roundList.map((e) => e.toJson()).toList()
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Creates a GameSession object from a JSON map.
|
/// Creates a GameSession object from a JSON map.
|
||||||
GameSession.fromJson(Map<String, dynamic> json)
|
GameSession.fromJson(Map<String, dynamic> json)
|
||||||
: gameTitle = json['gameTitle'],
|
: createdAt = DateTime.parse(json['createdAt']),
|
||||||
isPointsLimitEnabled = json['gameHasPointLimit'],
|
gameTitle = json['gameTitle'],
|
||||||
players = List<String>.from(json['players']),
|
players = List<String>.from(json['players']),
|
||||||
playerScores = List<int>.from(json['playerScores']),
|
pointLimit = json['pointLimit'],
|
||||||
roundNumber = json['roundNumber'],
|
caboPenalty = json['caboPenalty'],
|
||||||
|
isPointsLimitEnabled = json['gameHasPointLimit'],
|
||||||
isGameFinished = json['isGameFinished'],
|
isGameFinished = json['isGameFinished'],
|
||||||
winner = json['winner'],
|
winner = json['winner'],
|
||||||
|
roundNumber = json['roundNumber'],
|
||||||
|
playerScores = List<int>.from(json['playerScores']),
|
||||||
roundList =
|
roundList =
|
||||||
(json['roundList'] as List).map((e) => Round.fromJson(e)).toList();
|
(json['roundList'] as List).map((e) => Round.fromJson(e)).toList();
|
||||||
|
|
||||||
@@ -76,7 +85,7 @@ class GameSession {
|
|||||||
void applyKamikaze(int roundNum, int kamikazePlayerIndex) {
|
void applyKamikaze(int roundNum, int kamikazePlayerIndex) {
|
||||||
List<int> roundScores = List.generate(players.length, (_) => 0);
|
List<int> roundScores = List.generate(players.length, (_) => 0);
|
||||||
List<int> scoreUpdates = List.generate(players.length, (_) => 0);
|
List<int> scoreUpdates = List.generate(players.length, (_) => 0);
|
||||||
for (int i = 0; i < roundScores.length; i++) {
|
for (int i = 0; i < scoreUpdates.length; i++) {
|
||||||
if (i != kamikazePlayerIndex) {
|
if (i != kamikazePlayerIndex) {
|
||||||
scoreUpdates[i] += 50;
|
scoreUpdates[i] += 50;
|
||||||
}
|
}
|
||||||
@@ -213,13 +222,13 @@ class GameSession {
|
|||||||
/// It then checks if any player has exceeded 100 points. If so, it sets
|
/// It then checks if any player has exceeded 100 points. If so, it sets
|
||||||
/// isGameFinished to true and calls the _setWinner() method to determine
|
/// isGameFinished to true and calls the _setWinner() method to determine
|
||||||
/// the winner.
|
/// the winner.
|
||||||
void updatePoints() {
|
Future<void> updatePoints() async {
|
||||||
_sumPoints();
|
_sumPoints();
|
||||||
if (isPointsLimitEnabled) {
|
if (isPointsLimitEnabled) {
|
||||||
_checkHundredPointsReached();
|
_checkHundredPointsReached();
|
||||||
|
|
||||||
for (int i = 0; i < playerScores.length; i++) {
|
for (int i = 0; i < playerScores.length; i++) {
|
||||||
if (playerScores[i] > 100) {
|
if (playerScores[i] > pointLimit) {
|
||||||
isGameFinished = true;
|
isGameFinished = true;
|
||||||
print('${players[i]} hat die 100 Punkte ueberschritten, '
|
print('${players[i]} hat die 100 Punkte ueberschritten, '
|
||||||
'deswegen wurde das Spiel beendet');
|
'deswegen wurde das Spiel beendet');
|
||||||
@@ -245,7 +254,7 @@ class GameSession {
|
|||||||
/// the corresponding round update.
|
/// the corresponding round update.
|
||||||
void _checkHundredPointsReached() {
|
void _checkHundredPointsReached() {
|
||||||
for (int i = 0; i < players.length; i++) {
|
for (int i = 0; i < players.length; i++) {
|
||||||
if (playerScores[i] == 100) {
|
if (playerScores[i] == pointLimit) {
|
||||||
print('${players[i]} hat genau 100 Punkte erreicht und bekommt '
|
print('${players[i]} hat genau 100 Punkte erreicht und bekommt '
|
||||||
'deswegen 50 Punkte abgezogen');
|
'deswegen 50 Punkte abgezogen');
|
||||||
roundList[roundNumber - 1].scoreUpdates[i] -= 50;
|
roundList[roundNumber - 1].scoreUpdates[i] -= 50;
|
||||||
|
|||||||
@@ -1,47 +1,15 @@
|
|||||||
import 'package:cabo_counter/data/game_session.dart';
|
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/custom_theme.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/tab_view.dart';
|
import 'package:cabo_counter/views/tab_view.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
|
||||||
void main() {
|
Future<void> main() async {
|
||||||
/// FIXME Just for Debugging
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
/// Fills the game list with some test data.
|
await ConfigService.initConfig();
|
||||||
Globals.addGameSession(GameSession(
|
Globals.pointLimit = await ConfigService.getPointLimit();
|
||||||
gameTitle: 'Spiel am 27.02.2025',
|
Globals.caboPenalty = await ConfigService.getCaboPenalty();
|
||||||
players: ['Clara', 'Tobias', 'Yannik', 'Lena', 'Lekaia'],
|
|
||||||
isPointsLimitEnabled: true));
|
|
||||||
Globals.addGameSession(GameSession(
|
|
||||||
gameTitle: 'Freundschaftsrunde',
|
|
||||||
players: ['Felix', 'Jonas', 'Nils'],
|
|
||||||
isPointsLimitEnabled: false));
|
|
||||||
Globals.addGameSession(GameSession(
|
|
||||||
gameTitle: 'Familienabend',
|
|
||||||
players: ['Mama', 'Papa', 'Lisa'],
|
|
||||||
isPointsLimitEnabled: true,
|
|
||||||
));
|
|
||||||
Globals.addGameSession(GameSession(
|
|
||||||
gameTitle: 'Turnier 1. Runde',
|
|
||||||
players: ['Tim', 'Max', 'Sophie', 'Lena'],
|
|
||||||
isPointsLimitEnabled: false));
|
|
||||||
Globals.addGameSession(GameSession(
|
|
||||||
gameTitle: '2 Namen max length',
|
|
||||||
players: ['Heinrich', 'Johannes'],
|
|
||||||
isPointsLimitEnabled: true));
|
|
||||||
Globals.addGameSession(GameSession(
|
|
||||||
gameTitle: '3 Namen max length',
|
|
||||||
players: ['Benjamin', 'Stefanie', 'Wolfgang'],
|
|
||||||
isPointsLimitEnabled: false));
|
|
||||||
Globals.addGameSession(GameSession(
|
|
||||||
gameTitle: '4 Namen max length',
|
|
||||||
players: ['Leonhard', 'Mathilde', 'Bernhard', 'Gerlinde'],
|
|
||||||
isPointsLimitEnabled: true));
|
|
||||||
Globals.addGameSession(GameSession(
|
|
||||||
gameTitle: '5 Namen max length',
|
|
||||||
players: ['Hartmuth', 'Elisabet', 'Rosalind', 'Theresia', 'Karoline'],
|
|
||||||
isPointsLimitEnabled: false));
|
|
||||||
|
|
||||||
runApp(const App());
|
runApp(const App());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
57
lib/services/config_service.dart
Normal file
57
lib/services/config_service.dart
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import 'package:cabo_counter/utility/globals.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
|
/// This class handles the configuration settings for the app.
|
||||||
|
/// It uses SharedPreferences to store and retrieve the personal configuration of the app.
|
||||||
|
/// Currently it provides methods to initialize, get, and set the point limit and cabo penalty.
|
||||||
|
class ConfigService {
|
||||||
|
static const String _keyPointLimit = 'pointLimit';
|
||||||
|
static const String _keyCaboPenalty = 'caboPenalty';
|
||||||
|
static const int _defaultPointLimit = 100; // Default Value
|
||||||
|
static const int _defaultCaboPenalty = 5; // Default Value
|
||||||
|
|
||||||
|
static Future<void> initConfig() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
|
||||||
|
// Default values only set if they are not already set
|
||||||
|
prefs.setInt(
|
||||||
|
_keyPointLimit, prefs.getInt(_keyPointLimit) ?? _defaultPointLimit);
|
||||||
|
prefs.setInt(
|
||||||
|
_keyCaboPenalty, prefs.getInt(_keyCaboPenalty) ?? _defaultCaboPenalty);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Getter for the point limit.
|
||||||
|
static Future<int> getPointLimit() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
return prefs.getInt(_keyPointLimit) ?? _defaultPointLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Setter for the point limit.
|
||||||
|
/// [newPointLimit] is the new point limit to be set.
|
||||||
|
static Future<void> setPointLimit(int newPointLimit) async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.setInt(_keyPointLimit, newPointLimit);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Getter for the cabo penalty.
|
||||||
|
static Future<int> getCaboPenalty() async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
return prefs.getInt(_keyCaboPenalty) ?? _defaultCaboPenalty;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Setter for the cabo penalty.
|
||||||
|
/// [newCaboPenalty] is the new cabo penalty to be set.
|
||||||
|
static Future<void> setCaboPenalty(int newCaboPenalty) async {
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.setInt(_keyCaboPenalty, newCaboPenalty);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Resets the configuration to default values.
|
||||||
|
static Future<void> resetConfig() async {
|
||||||
|
Globals.pointLimit = _defaultPointLimit;
|
||||||
|
Globals.caboPenalty = _defaultCaboPenalty;
|
||||||
|
final prefs = await SharedPreferences.getInstance();
|
||||||
|
await prefs.setInt(_keyPointLimit, _defaultPointLimit);
|
||||||
|
await prefs.setInt(_keyCaboPenalty, _defaultCaboPenalty);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ class CustomTheme {
|
|||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
);
|
);
|
||||||
|
|
||||||
static TextStyle createGameTitle = TextStyle(
|
static TextStyle rowTitle = TextStyle(
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
color: primaryColor,
|
color: primaryColor,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
@@ -27,10 +27,4 @@ class CustomTheme {
|
|||||||
color: white,
|
color: white,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
);
|
);
|
||||||
|
|
||||||
static TextStyle roundPlayers = TextStyle(
|
|
||||||
fontSize: 20,
|
|
||||||
color: white,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,4 +8,10 @@ class Globals {
|
|||||||
gameList.add(session);
|
gameList.add(session);
|
||||||
gameList.sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
gameList.sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int pointLimit = 100;
|
||||||
|
|
||||||
|
static int caboPenalty = 5;
|
||||||
|
|
||||||
|
static String appDevPhase = 'Alpha';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
|
padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
|
||||||
child: Text(
|
child: Text(
|
||||||
'Spieler:innen',
|
'Spieler:innen',
|
||||||
style: CustomTheme.createGameTitle,
|
style: CustomTheme.rowTitle,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
ListView.builder(
|
ListView.builder(
|
||||||
@@ -61,7 +61,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
|
padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
|
||||||
child: Text(
|
child: Text(
|
||||||
'Runden',
|
'Runden',
|
||||||
style: CustomTheme.createGameTitle,
|
style: CustomTheme.rowTitle,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
ListView.builder(
|
ListView.builder(
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import 'package:cabo_counter/data/game_session.dart';
|
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/custom_theme.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/mode_selection_view.dart';
|
import 'package:cabo_counter/views/mode_selection_view.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
@@ -44,11 +44,11 @@ class _CreateGameState extends State<CreateGame> {
|
|||||||
padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
|
padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
|
||||||
child: Text(
|
child: Text(
|
||||||
'Spiel',
|
'Spiel',
|
||||||
style: CustomTheme.createGameTitle,
|
style: CustomTheme.rowTitle,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
|
padding: const EdgeInsets.fromLTRB(15, 10, 10, 0),
|
||||||
child: CupertinoTextField(
|
child: CupertinoTextField(
|
||||||
decoration: const BoxDecoration(),
|
decoration: const BoxDecoration(),
|
||||||
maxLength: 16,
|
maxLength: 16,
|
||||||
@@ -60,7 +60,7 @@ class _CreateGameState extends State<CreateGame> {
|
|||||||
),
|
),
|
||||||
// Spielmodus-Auswahl mit Chevron
|
// Spielmodus-Auswahl mit Chevron
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(10, 10, 10, 0),
|
padding: const EdgeInsets.fromLTRB(15, 10, 10, 0),
|
||||||
child: CupertinoTextField(
|
child: CupertinoTextField(
|
||||||
decoration: const BoxDecoration(),
|
decoration: const BoxDecoration(),
|
||||||
readOnly: true,
|
readOnly: true,
|
||||||
@@ -77,15 +77,15 @@ class _CreateGameState extends State<CreateGame> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
// Öffne das Modus-Auswahlmenü
|
|
||||||
final selected = await Navigator.push(
|
final selected = await Navigator.push(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
builder: (context) => const ModeSelectionMenu(),
|
builder: (context) => ModeSelectionMenu(
|
||||||
|
pointLimit: Globals.pointLimit,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Aktualisiere den ausgewählten Modus
|
|
||||||
if (selected != null) {
|
if (selected != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
selectedMode = selected;
|
selectedMode = selected;
|
||||||
@@ -98,7 +98,7 @@ class _CreateGameState extends State<CreateGame> {
|
|||||||
padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
|
padding: const EdgeInsets.fromLTRB(10, 10, 0, 0),
|
||||||
child: Text(
|
child: Text(
|
||||||
'Spieler:innen',
|
'Spieler:innen',
|
||||||
style: CustomTheme.createGameTitle,
|
style: CustomTheme.rowTitle,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
@@ -282,17 +282,24 @@ class _CreateGameState extends State<CreateGame> {
|
|||||||
players.add(controller.text);
|
players.add(controller.text);
|
||||||
}
|
}
|
||||||
GameSession gameSession = GameSession(
|
GameSession gameSession = GameSession(
|
||||||
|
createdAt: DateTime.now(),
|
||||||
gameTitle: _gameTitleTextController.text,
|
gameTitle: _gameTitleTextController.text,
|
||||||
players: players,
|
players: players,
|
||||||
|
pointLimit: Globals.pointLimit,
|
||||||
|
caboPenalty: Globals.caboPenalty,
|
||||||
isPointsLimitEnabled: selectedMode!,
|
isPointsLimitEnabled: selectedMode!,
|
||||||
);
|
);
|
||||||
Globals.addGameSession(gameSession);
|
Globals.addGameSession(gameSession);
|
||||||
LocalStorageService.saveGameSessions();
|
LocalStorageService.saveGameSessions();
|
||||||
|
if (context.mounted) {
|
||||||
Navigator.pushReplacement(
|
Navigator.pushReplacement(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
builder: (context) =>
|
builder: (context) =>
|
||||||
ActiveGameView(gameSession: gameSession)));
|
ActiveGameView(gameSession: gameSession)));
|
||||||
|
} else {
|
||||||
|
print('Context is not mounted');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import 'package:cabo_counter/utility/local_storage_service.dart';
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
@@ -30,7 +29,7 @@ class InformationView extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding:
|
padding:
|
||||||
const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
|
const EdgeInsets.symmetric(horizontal: 20, vertical: 30),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 200,
|
height: 200,
|
||||||
child: Image.asset('assets/cabo-counter-logo_rounded.png'),
|
child: Image.asset('assets/cabo-counter-logo_rounded.png'),
|
||||||
@@ -51,7 +50,7 @@ class InformationView extends StatelessWidget {
|
|||||||
softWrap: true,
|
softWrap: true,
|
||||||
)),
|
)),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 15,
|
height: 30,
|
||||||
),
|
),
|
||||||
const Text(
|
const Text(
|
||||||
'\u00A9 Felix Kirchner',
|
'\u00A9 Felix Kirchner',
|
||||||
@@ -74,53 +73,6 @@ class InformationView extends StatelessWidget {
|
|||||||
icon: const Icon(FontAwesomeIcons.github)),
|
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),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
],
|
],
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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/custom_theme.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/settings_view.dart';
|
import 'package:cabo_counter/views/settings_view.dart';
|
||||||
@@ -16,17 +16,23 @@ class MainMenuView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _MainMenuViewState extends State<MainMenuView> {
|
class _MainMenuViewState extends State<MainMenuView> {
|
||||||
|
bool _isLoading = true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
initState() {
|
initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
LocalStorageService.loadGameSessions().then((_) {
|
LocalStorageService.loadGameSessions().then((_) {
|
||||||
setState(() {});
|
setState(() {
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
print('MainMenuView build');
|
||||||
LocalStorageService.loadGameSessions();
|
LocalStorageService.loadGameSessions();
|
||||||
|
|
||||||
return CupertinoPageScaffold(
|
return CupertinoPageScaffold(
|
||||||
resizeToAvoidBottomInset: false,
|
resizeToAvoidBottomInset: false,
|
||||||
navigationBar: CupertinoNavigationBar(
|
navigationBar: CupertinoNavigationBar(
|
||||||
@@ -57,7 +63,9 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
),
|
),
|
||||||
child: CupertinoPageScaffold(
|
child: CupertinoPageScaffold(
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
child: Globals.gameList.isEmpty
|
child: _isLoading
|
||||||
|
? const Center(child: CupertinoActivityIndicator())
|
||||||
|
: Globals.gameList.isEmpty
|
||||||
? Column(
|
? Column(
|
||||||
mainAxisAlignment:
|
mainAxisAlignment:
|
||||||
MainAxisAlignment.center, // Oben ausrichten
|
MainAxisAlignment.center, // Oben ausrichten
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import 'package:cabo_counter/utility/custom_theme.dart';
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
|
||||||
class ModeSelectionMenu extends StatelessWidget {
|
class ModeSelectionMenu extends StatelessWidget {
|
||||||
const ModeSelectionMenu({super.key});
|
final int pointLimit;
|
||||||
|
const ModeSelectionMenu({super.key, required this.pointLimit});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@@ -15,9 +16,9 @@ class ModeSelectionMenu extends StatelessWidget {
|
|||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(0, 16, 0, 0),
|
padding: const EdgeInsets.fromLTRB(0, 16, 0, 0),
|
||||||
child: CupertinoListTile(
|
child: CupertinoListTile(
|
||||||
title: Text('101 Punkte', style: CustomTheme.modeTitle),
|
title: Text('$pointLimit Punkte', style: CustomTheme.modeTitle),
|
||||||
subtitle: const Text(
|
subtitle: Text(
|
||||||
'Es wird solange gespielt, bis einer Spieler mehr als 100 Punkte erreicht',
|
'Es wird solange gespielt, bis einer Spieler mehr als $pointLimit Punkte erreicht',
|
||||||
style: CustomTheme.modeDescription,
|
style: CustomTheme.modeDescription,
|
||||||
maxLines: 3,
|
maxLines: 3,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:cabo_counter/data/game_session.dart';
|
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/custom_theme.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';
|
||||||
|
|||||||
@@ -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: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 +15,13 @@ class SettingsView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SettingsViewState extends State<SettingsView> {
|
class _SettingsViewState extends State<SettingsView> {
|
||||||
|
UniqueKey _stepperKey1 = UniqueKey();
|
||||||
|
UniqueKey _stepperKey2 = UniqueKey();
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return CupertinoPageScaffold(
|
return CupertinoPageScaffold(
|
||||||
@@ -18,27 +31,177 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
const Column(
|
Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
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,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Center(
|
CupertinoButton(
|
||||||
child: Icon(
|
color: CustomTheme.primaryColor,
|
||||||
CupertinoIcons.settings,
|
sizeStyle: CupertinoButtonSize.medium,
|
||||||
size: 100,
|
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(
|
Positioned(
|
||||||
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, 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(),
|
future: _getPackageInfo(),
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
return Text(
|
return Text(
|
||||||
'Alpha ${snapshot.data!.version} '
|
'${Globals.appDevPhase} ${snapshot.data!.version} '
|
||||||
'(Build ${snapshot.data!.buildNumber})',
|
'(Build ${snapshot.data!.buildNumber})',
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
);
|
);
|
||||||
@@ -53,6 +216,8 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
)),
|
)),
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
|
|||||||
73
lib/widgets/stepper.dart
Normal file
73
lib/widgets/stepper.dart
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
import 'package:flutter/cupertino.dart'; // Für iOS-Style
|
||||||
|
|
||||||
|
class Stepper extends StatefulWidget {
|
||||||
|
final int minValue;
|
||||||
|
final int maxValue;
|
||||||
|
final int? initialValue;
|
||||||
|
final int step;
|
||||||
|
final ValueChanged<int> onChanged;
|
||||||
|
const Stepper({
|
||||||
|
super.key,
|
||||||
|
required this.minValue,
|
||||||
|
required this.maxValue,
|
||||||
|
required this.step,
|
||||||
|
required this.onChanged,
|
||||||
|
this.initialValue,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
// ignore: library_private_types_in_public_api
|
||||||
|
_StepperState createState() => _StepperState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _StepperState extends State<Stepper> {
|
||||||
|
late int _value;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
final start = widget.initialValue ?? widget.minValue;
|
||||||
|
_value = start.clamp(widget.minValue, widget.maxValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Row(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
CupertinoButton(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
onPressed: _decrement,
|
||||||
|
child: const Icon(CupertinoIcons.minus),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 12.0),
|
||||||
|
child: Text('$_value', style: const TextStyle(fontSize: 18)),
|
||||||
|
),
|
||||||
|
CupertinoButton(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
onPressed: _increment,
|
||||||
|
child: const Icon(CupertinoIcons.add),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _increment() {
|
||||||
|
if (_value + widget.step <= widget.maxValue) {
|
||||||
|
setState(() {
|
||||||
|
_value += widget.step;
|
||||||
|
widget.onChanged.call(_value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _decrement() {
|
||||||
|
if (_value - widget.step >= widget.minValue) {
|
||||||
|
setState(() {
|
||||||
|
_value -= widget.step;
|
||||||
|
widget.onChanged.call(_value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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.5+116
|
version: 0.1.6-alpha+138
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.5.4
|
sdk: ^3.5.4
|
||||||
@@ -20,6 +20,7 @@ dependencies:
|
|||||||
typed_data: ^1.3.2
|
typed_data: ^1.3.2
|
||||||
url_launcher: any
|
url_launcher: any
|
||||||
json_schema: ^5.2.1
|
json_schema: ^5.2.1
|
||||||
|
shared_preferences: ^2.5.3
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
Reference in New Issue
Block a user