Implemented deletion button
This commit is contained in:
@@ -65,6 +65,7 @@ class _AppState extends State<App> with WidgetsBindingObserver {
|
|||||||
return supportedLocales.first;
|
return supportedLocales.first;
|
||||||
},
|
},
|
||||||
theme: CupertinoThemeData(
|
theme: CupertinoThemeData(
|
||||||
|
applyThemeToAll: true,
|
||||||
brightness: Brightness.dark,
|
brightness: Brightness.dark,
|
||||||
primaryColor: CustomTheme.primaryColor,
|
primaryColor: CustomTheme.primaryColor,
|
||||||
scaffoldBackgroundColor: CustomTheme.backgroundColor,
|
scaffoldBackgroundColor: CustomTheme.backgroundColor,
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:cabo_counter/data/game_manager.dart';
|
||||||
import 'package:cabo_counter/data/game_session.dart';
|
import 'package:cabo_counter/data/game_session.dart';
|
||||||
import 'package:cabo_counter/l10n/app_localizations.dart';
|
import 'package:cabo_counter/l10n/app_localizations.dart';
|
||||||
import 'package:cabo_counter/utility/custom_theme.dart';
|
import 'package:cabo_counter/utility/custom_theme.dart';
|
||||||
@@ -17,15 +18,24 @@ class ActiveGameView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ActiveGameViewState extends State<ActiveGameView> {
|
class _ActiveGameViewState extends State<ActiveGameView> {
|
||||||
|
late final GameSession gameSession;
|
||||||
|
bool _deleted = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
gameSession = widget.gameSession;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListenableBuilder(
|
return ListenableBuilder(
|
||||||
listenable: widget.gameSession,
|
listenable: gameSession,
|
||||||
builder: (context, _) {
|
builder: (context, _) {
|
||||||
List<int> sortedPlayerIndices = _getSortedPlayerIndices();
|
List<int> sortedPlayerIndices = _getSortedPlayerIndices();
|
||||||
return CupertinoPageScaffold(
|
return CupertinoPageScaffold(
|
||||||
navigationBar: CupertinoNavigationBar(
|
navigationBar: CupertinoNavigationBar(
|
||||||
middle: Text(widget.gameSession.gameTitle),
|
middle: Text(gameSession.gameTitle),
|
||||||
),
|
),
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
@@ -42,7 +52,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
ListView.builder(
|
ListView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
itemCount: widget.gameSession.players.length,
|
itemCount: gameSession.players.length,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
int playerIndex = sortedPlayerIndices[index];
|
int playerIndex = sortedPlayerIndices[index];
|
||||||
return CupertinoListTile(
|
return CupertinoListTile(
|
||||||
@@ -51,7 +61,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
_getPlacementPrefix(index),
|
_getPlacementPrefix(index),
|
||||||
const SizedBox(width: 5),
|
const SizedBox(width: 5),
|
||||||
Text(
|
Text(
|
||||||
widget.gameSession.players[playerIndex],
|
gameSession.players[playerIndex],
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontWeight: FontWeight.bold),
|
fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
@@ -60,8 +70,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
trailing: Row(
|
trailing: Row(
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(width: 5),
|
const SizedBox(width: 5),
|
||||||
Text(
|
Text('${gameSession.playerScores[playerIndex]} '
|
||||||
'${widget.gameSession.playerScores[playerIndex]} '
|
|
||||||
'${AppLocalizations.of(context).points}')
|
'${AppLocalizations.of(context).points}')
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -78,7 +87,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
ListView.builder(
|
ListView.builder(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
itemCount: widget.gameSession.roundNumber,
|
itemCount: gameSession.roundNumber,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(1),
|
padding: const EdgeInsets.all(1),
|
||||||
@@ -88,10 +97,9 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
title: Text(
|
title: Text(
|
||||||
'${AppLocalizations.of(context).round} ${index + 1}',
|
'${AppLocalizations.of(context).round} ${index + 1}',
|
||||||
),
|
),
|
||||||
trailing: index + 1 !=
|
trailing:
|
||||||
widget.gameSession.roundNumber ||
|
index + 1 != gameSession.roundNumber ||
|
||||||
widget.gameSession.isGameFinished ==
|
gameSession.isGameFinished == true
|
||||||
true
|
|
||||||
? (const Text('\u{2705}',
|
? (const Text('\u{2705}',
|
||||||
style: TextStyle(fontSize: 22)))
|
style: TextStyle(fontSize: 22)))
|
||||||
: const Text('\u{23F3}',
|
: const Text('\u{23F3}',
|
||||||
@@ -104,7 +112,7 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
fullscreenDialog: true,
|
fullscreenDialog: true,
|
||||||
builder: (context) => RoundView(
|
builder: (context) => RoundView(
|
||||||
gameSession: widget.gameSession,
|
gameSession: gameSession,
|
||||||
roundNumber: index + 1),
|
roundNumber: index + 1),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -129,17 +137,21 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
),
|
),
|
||||||
onTap: () => Navigator.push(
|
onTap: () => Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
CupertinoPageRoute(
|
||||||
builder: (_) => GraphView(
|
builder: (_) => GraphView(
|
||||||
gameSession: widget.gameSession,
|
gameSession: gameSession,
|
||||||
)))),
|
)))),
|
||||||
CupertinoListTile(
|
CupertinoListTile(
|
||||||
title:
|
title: Text(
|
||||||
Text(AppLocalizations.of(context).delete_game,
|
AppLocalizations.of(context).delete_game,
|
||||||
style: const TextStyle(
|
),
|
||||||
color: Colors.white30,
|
onTap: () {
|
||||||
)),
|
_showDeleteGameDialog().then((value) {
|
||||||
onTap: () {},
|
if (value) {
|
||||||
|
_removeGameSession(gameSession);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
),
|
),
|
||||||
CupertinoListTile(
|
CupertinoListTile(
|
||||||
title: Text(
|
title: Text(
|
||||||
@@ -151,12 +163,11 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
context,
|
context,
|
||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
builder: (_) => CreateGameView(
|
builder: (_) => CreateGameView(
|
||||||
gameTitle:
|
gameTitle: gameSession.gameTitle,
|
||||||
widget.gameSession.gameTitle,
|
|
||||||
isPointsLimitEnabled: widget
|
isPointsLimitEnabled: widget
|
||||||
.gameSession
|
.gameSession
|
||||||
.isPointsLimitEnabled,
|
.isPointsLimitEnabled,
|
||||||
players: widget.gameSession.players,
|
players: gameSession.players,
|
||||||
)));
|
)));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -180,11 +191,11 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
/// ascending order.
|
/// ascending order.
|
||||||
List<int> _getSortedPlayerIndices() {
|
List<int> _getSortedPlayerIndices() {
|
||||||
List<int> playerIndices =
|
List<int> playerIndices =
|
||||||
List<int>.generate(widget.gameSession.players.length, (index) => index);
|
List<int>.generate(gameSession.players.length, (index) => index);
|
||||||
// Sort the indices based on the summed points
|
// Sort the indices based on the summed points
|
||||||
playerIndices.sort((a, b) {
|
playerIndices.sort((a, b) {
|
||||||
int scoreA = widget.gameSession.playerScores[a];
|
int scoreA = gameSession.playerScores[a];
|
||||||
int scoreB = widget.gameSession.playerScores[b];
|
int scoreB = gameSession.playerScores[b];
|
||||||
return scoreA.compareTo(scoreB);
|
return scoreA.compareTo(scoreB);
|
||||||
});
|
});
|
||||||
return playerIndices;
|
return playerIndices;
|
||||||
@@ -217,4 +228,56 @@ class _ActiveGameViewState extends State<ActiveGameView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> _showDeleteGameDialog() async {
|
||||||
|
return await showCupertinoDialog<bool>(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return CupertinoAlertDialog(
|
||||||
|
title: Text(AppLocalizations.of(context).delete_game),
|
||||||
|
content: Text(
|
||||||
|
'Möchtes du das Spiel "${gameSession.gameTitle}" wirklich löschen?'),
|
||||||
|
actions: [
|
||||||
|
CupertinoDialogAction(
|
||||||
|
child: Text(AppLocalizations.of(context).cancel),
|
||||||
|
onPressed: () => Navigator.pop(context, false),
|
||||||
|
),
|
||||||
|
CupertinoDialogAction(
|
||||||
|
child: Text(AppLocalizations.of(context).delete),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context, true);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
) ??
|
||||||
|
false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _removeGameSession(GameSession gameSession) async {
|
||||||
|
if (gameManager.gameExistsInGameList(gameSession.id)) {
|
||||||
|
Navigator.pop(context);
|
||||||
|
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
gameManager.removeGameSessionById(gameSession.id);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
showCupertinoDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return CupertinoAlertDialog(
|
||||||
|
title: const Text('ID Fehler'),
|
||||||
|
content: const Text(
|
||||||
|
'Das Spiel hat bisher noch keine ID zugewiesen bekommen. Falls du das Spiel löschen möchtest, mache das bitte über das Hauptmenü. Alle neu erstellten Spiele haben eine ID.'),
|
||||||
|
actions: [
|
||||||
|
CupertinoDialogAction(
|
||||||
|
child: Text(AppLocalizations.of(context).ok),
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.3.5+269
|
version: 0.3.5+312
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.5.4
|
sdk: ^3.5.4
|
||||||
@@ -26,6 +26,7 @@ dependencies:
|
|||||||
sdk: flutter
|
sdk: flutter
|
||||||
intl: any
|
intl: any
|
||||||
syncfusion_flutter_charts: ^30.1.37
|
syncfusion_flutter_charts: ^30.1.37
|
||||||
|
uuid: ^4.5.1
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
Reference in New Issue
Block a user