Fixed merge issues

This commit is contained in:
2025-07-20 17:07:55 +02:00
parent fbfed8e013
commit 651b3eab0f
2 changed files with 184 additions and 119 deletions

View File

@@ -137,127 +137,127 @@ class _CreateGameViewState extends State<CreateGameView> {
), ),
), ),
Expanded( Expanded(
child: ReorderableListView.builder( child: ReorderableListView.builder(
physics: const NeverScrollableScrollPhysics(), physics: const NeverScrollableScrollPhysics(),
itemCount: _playerNameTextControllers.length + 2, itemCount: _playerNameTextControllers.length + 2,
onReorder: (oldIndex, newIndex) { onReorder: (oldIndex, newIndex) {
if (oldIndex < _playerNameTextControllers.length && if (oldIndex < _playerNameTextControllers.length &&
newIndex <= _playerNameTextControllers.length) { newIndex <= _playerNameTextControllers.length) {
setState(() { setState(() {
if (newIndex > oldIndex) newIndex--; if (newIndex > oldIndex) newIndex--;
final item = final item =
_playerNameTextControllers.removeAt(oldIndex); _playerNameTextControllers.removeAt(oldIndex);
_playerNameTextControllers.insert(newIndex, item); _playerNameTextControllers.insert(newIndex, item);
}); });
} }
}, },
itemBuilder: (context, index) { itemBuilder: (context, index) {
// Create game button // Create game button
if (index == _playerNameTextControllers.length + 1) { if (index == _playerNameTextControllers.length + 1) {
return Container( return Container(
key: const ValueKey('create_game_button'), key: const ValueKey('create_game_button'),
child: CupertinoButton( child: CupertinoButton(
padding: const EdgeInsets.fromLTRB(0, 50, 0, 0), padding: const EdgeInsets.fromLTRB(0, 50, 0, 0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Container( Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
color: CustomTheme.primaryColor, color: CustomTheme.primaryColor,
), ),
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
horizontal: 15, vertical: 8), horizontal: 15, vertical: 8),
child: Text( child: Text(
AppLocalizations.of(context).create_game, AppLocalizations.of(context).create_game,
style: TextStyle( style: TextStyle(
color: CustomTheme.backgroundColor, color: CustomTheme.backgroundColor,
),
),
), ),
), ],
),
],
),
onPressed: () {
_checkAllGameAttributes();
},
),
);
}
// Add player button
if (index == _playerNameTextControllers.length) {
return Container(
key: const ValueKey('add_player_button'),
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 4.0, horizontal: 10),
child: CupertinoButton(
padding: EdgeInsets.zero,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
CupertinoIcons.add_circled_solid,
color: CustomTheme.primaryColor,
),
const SizedBox(width: 6),
Text(
AppLocalizations.of(context).add_player,
style:
TextStyle(color: CustomTheme.primaryColor),
),
),
],
),
onPressed: () {
if (_playerNameTextControllers.length < maxPlayers) {
setState(() {
_playerNameTextControllers
.add(TextEditingController());
});
} else {
showFeedbackDialog(CreateStatus.maxPlayers);
}
},
),
);
} else {
// Spieler-Einträge
return Padding(
padding: const EdgeInsets.symmetric(
vertical: 8.0, horizontal: 5),
child: Row(
children: [
CupertinoButton(
padding: EdgeInsets.zero,
child: const Icon(
CupertinoIcons.minus_circle_fill,
color: CupertinoColors.destructiveRed,
size: 25,
), ),
onPressed: () { onPressed: () {
setState(() { _checkAllGameAttributes();
_playerNameTextControllers[index].dispose();
_playerNameTextControllers.removeAt(index);
});
}, },
), ),
Expanded( );
child: CupertinoTextField( }
controller: _playerNameTextControllers[index], // Add player button
maxLength: 12, if (index == _playerNameTextControllers.length) {
placeholder: return Container(
'${AppLocalizations.of(context).player} ${index + 1}', key: const ValueKey('add_player_button'),
padding: const EdgeInsets.all(12), child: Padding(
decoration: const BoxDecoration(), padding: const EdgeInsets.symmetric(
), vertical: 4.0, horizontal: 10),
child: CupertinoButton(
padding: EdgeInsets.zero,
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Icon(
CupertinoIcons.add_circled_solid,
color: CustomTheme.primaryColor,
),
const SizedBox(width: 6),
Text(
AppLocalizations.of(context)
.add_player,
style: TextStyle(
color:
CustomTheme.primaryColor),
),
]),
onPressed: () {
if (_playerNameTextControllers.length <
maxPlayers) {
setState(() {
_playerNameTextControllers
.add(TextEditingController());
});
} else {
showFeedbackDialog(
CreateStatus.maxPlayers);
}
})));
} else {
// Player entries
return Padding(
key: ValueKey(_playerNameTextControllers[index]),
padding: const EdgeInsets.symmetric(
vertical: 8.0, horizontal: 5),
child: Row(
children: [
CupertinoButton(
padding: EdgeInsets.zero,
child: const Icon(
CupertinoIcons.minus_circle_fill,
color: CupertinoColors.destructiveRed,
size: 25,
),
onPressed: () {
setState(() {
_playerNameTextControllers[index].dispose();
_playerNameTextControllers.removeAt(index);
});
},
),
Expanded(
child: CupertinoTextField(
controller: _playerNameTextControllers[index],
maxLength: 12,
placeholder:
'${AppLocalizations.of(context).player} ${index + 1}',
padding: const EdgeInsets.all(12),
decoration: const BoxDecoration(),
),
),
],
), ),
), );
], }
), })),
);
},
),
),
Center( Center(
child: CupertinoButton( child: CupertinoButton(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
@@ -319,18 +319,26 @@ class _CreateGameViewState extends State<CreateGameView> {
), ),
], ],
)))); ))));
}
Future<void> _createGame() async { Future<void> _createGame() async {
/*var uuid = const Uuid();
id = uuid.v1();*/
List<String> players = []; List<String> players = [];
for (var controller in _playerNameTextControllers) { for (var controller in _playerNameTextControllers) {
players.add(controller.text); players.add(controller.text);
} }
bool isPointsLimitEnabled = gameMode == GameMode.pointLimit;
GameSession gameSession = GameSession( GameSession gameSession = GameSession(
createdAt: DateTime.now(), createdAt: DateTime.now(),
gameTitle: _gameTitleTextController.text, gameTitle: _gameTitleTextController.text,
players: players, players: players,
pointLimit: Globals.pointLimit, pointLimit: ConfigService.getPointLimit(),
caboPenalty: Globals.caboPenalty, caboPenalty: ConfigService.getCaboPenalty(),
isPointsLimitEnabled: _isPointsLimitEnabled!, isPointsLimitEnabled: isPointsLimitEnabled,
); );
final index = await gameManager.addGameSession(gameSession); final index = await gameManager.addGameSession(gameSession);
final session = gameManager.gameList[index]; final session = gameManager.gameList[index];
@@ -361,6 +369,63 @@ class _CreateGameViewState extends State<CreateGameView> {
}); });
} }
void _checkAllGameAttributes() {
if (_gameTitleTextController.text == '') {
_showDialog((
AppLocalizations.of(context).no_gameTitle_title,
AppLocalizations.of(context).no_gameTitle_message
));
return;
}
if (gameMode == GameMode.none) {
_showDialog(
(
AppLocalizations.of(context).no_mode_title,
AppLocalizations.of(context).no_mode_message
),
);
return;
}
if (_playerNameTextControllers.length < 2) {
_showDialog(
(
AppLocalizations.of(context).min_players_title,
AppLocalizations.of(context).min_players_message
),
);
return;
}
if (!everyPlayerHasAName()) {
_showDialog((
AppLocalizations.of(context).no_name_title,
AppLocalizations.of(context).no_name_message
));
return;
}
_createGame();
}
void _showDialog((String, String) content) {
final (title, message) = content;
showCupertinoDialog(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text(title),
content: Text(message),
actions: [
CupertinoDialogAction(
child: Text(AppLocalizations.of(context).ok),
onPressed: () => Navigator.pop(context),
),
],
),
);
}
/// Returns the title and message for the dialog based on the [CreateStatus]. /// Returns the title and message for the dialog based on the [CreateStatus].
(String, String) _getDialogContent(CreateStatus status) { (String, String) _getDialogContent(CreateStatus status) {
switch (status) { switch (status) {

View File

@@ -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.5.0+554 version: 0.5.0+556
environment: environment:
sdk: ^3.5.4 sdk: ^3.5.4