Added global variables for local config

This commit is contained in:
Felix Kirchner
2025-05-03 15:48:03 +02:00
parent 7a9747b78c
commit 037a1e2cd7
4 changed files with 17 additions and 11 deletions

View File

@@ -1,12 +1,15 @@
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/views/tab_view.dart';
import 'package:flutter/cupertino.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await ConfigService.initConfig();
Globals.pointLimit = await ConfigService.getPointLimit();
Globals.caboPenalty = await ConfigService.getCaboPenalty();
runApp(const App());
}

View File

@@ -8,4 +8,7 @@ class Globals {
gameList.add(session);
gameList.sort((a, b) => b.createdAt.compareTo(a.createdAt));
}
static int pointLimit = 100;
static int caboPenalty = 5;
}

View File

@@ -1,5 +1,4 @@
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/globals.dart';
@@ -78,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;
@@ -207,7 +206,7 @@ class _CreateGameState extends State<CreateGame> {
),
],
),
onPressed: () async {
onPressed: () {
if (_gameTitleTextController.text == '') {
showCupertinoDialog(
context: context,
@@ -286,8 +285,8 @@ class _CreateGameState extends State<CreateGame> {
createdAt: DateTime.now(),
gameTitle: _gameTitleTextController.text,
players: players,
pointLimit: await ConfigService.getPointLimit(),
caboPenalty: await ConfigService.getCaboPenalty(),
pointLimit: Globals.pointLimit,
caboPenalty: Globals.caboPenalty,
isPointsLimitEnabled: selectedMode!,
);
Globals.addGameSession(gameSession);

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,
),