Added global variables for local config
This commit is contained in:
@@ -1,12 +1,15 @@
|
|||||||
import 'package:cabo_counter/services/config_service.dart';
|
import 'package:cabo_counter/services/config_service.dart';
|
||||||
import 'package:cabo_counter/services/local_storage_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/views/tab_view.dart';
|
import 'package:cabo_counter/views/tab_view.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await ConfigService.initConfig();
|
await ConfigService.initConfig();
|
||||||
|
Globals.pointLimit = await ConfigService.getPointLimit();
|
||||||
|
Globals.caboPenalty = await ConfigService.getCaboPenalty();
|
||||||
runApp(const App());
|
runApp(const App());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,4 +8,7 @@ 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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import 'package:cabo_counter/data/game_session.dart';
|
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/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';
|
||||||
@@ -78,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;
|
||||||
@@ -207,7 +206,7 @@ class _CreateGameState extends State<CreateGame> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: () {
|
||||||
if (_gameTitleTextController.text == '') {
|
if (_gameTitleTextController.text == '') {
|
||||||
showCupertinoDialog(
|
showCupertinoDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@@ -286,8 +285,8 @@ class _CreateGameState extends State<CreateGame> {
|
|||||||
createdAt: DateTime.now(),
|
createdAt: DateTime.now(),
|
||||||
gameTitle: _gameTitleTextController.text,
|
gameTitle: _gameTitleTextController.text,
|
||||||
players: players,
|
players: players,
|
||||||
pointLimit: await ConfigService.getPointLimit(),
|
pointLimit: Globals.pointLimit,
|
||||||
caboPenalty: await ConfigService.getCaboPenalty(),
|
caboPenalty: Globals.caboPenalty,
|
||||||
isPointsLimitEnabled: selectedMode!,
|
isPointsLimitEnabled: selectedMode!,
|
||||||
);
|
);
|
||||||
Globals.addGameSession(gameSession);
|
Globals.addGameSession(gameSession);
|
||||||
|
|||||||
@@ -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,
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user