Removed old deletion way

This commit is contained in:
2025-06-08 01:12:12 +02:00
parent d71585b585
commit 16e8d6ad15

View File

@@ -17,7 +17,6 @@ class MainMenuView extends StatefulWidget {
class _MainMenuViewState extends State<MainMenuView> {
bool _isLoading = true;
bool _isDeletionModeEnabled = false;
@override
initState() {
@@ -46,14 +45,10 @@ class _MainMenuViewState extends State<MainMenuView> {
),
);
},
icon: _isDeletionModeEnabled
? const Icon(null)
: const Icon(CupertinoIcons.settings, size: 30)),
icon: const Icon(CupertinoIcons.settings, size: 30)),
middle: const Text('Cabo Counter'),
trailing: IconButton(
onPressed: () => _isDeletionModeEnabled
? _showDeleteAllGamesPopup()
: {
onPressed: () => {
Navigator.push(
context,
CupertinoPageRoute(
@@ -61,9 +56,7 @@ class _MainMenuViewState extends State<MainMenuView> {
),
)
},
icon: _isDeletionModeEnabled
? const Icon(CupertinoIcons.trash, size: 25)
: const Icon(CupertinoIcons.add)),
icon: const Icon(CupertinoIcons.add)),
),
child: CupertinoPageScaffold(
child: SafeArea(
@@ -95,23 +88,7 @@ class _MainMenuViewState extends State<MainMenuView> {
),
],
)
: GestureDetector(
onTap: () => {
if (_isDeletionModeEnabled)
{
setState(() {
_isDeletionModeEnabled = false;
}),
print('Deletion mode: $_isDeletionModeEnabled')
}
},
onLongPress: () => {
setState(() {
_isDeletionModeEnabled = true;
}),
print('Deletion mode: $_isDeletionModeEnabled')
},
child: ListView.builder(
: ListView.builder(
itemCount: Globals.gameList.length,
itemBuilder: (context, index) {
final session = Globals.gameList[index];
@@ -128,15 +105,18 @@ class _MainMenuViewState extends State<MainMenuView> {
),
direction: DismissDirection.startToEnd,
confirmDismiss: (direction) async {
if (_isDeletionModeEnabled) return false;
return await _showDeleteSingleGamePopup(index);
final String gameTitle =
Globals.gameList[index].gameTitle;
return await _showDeleteGamePopup(gameTitle);
},
onDismissed: (direction) {
_deleteSpecificGame(index);
},
dismissThresholds: const {
DismissDirection.startToEnd: 0.6
},
child: Padding(
padding:
const EdgeInsets.symmetric(vertical: 10.0),
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: CupertinoListTile(
title: Text(session.gameTitle),
subtitle: session.isGameFinished == true
@@ -160,17 +140,13 @@ class _MainMenuViewState extends State<MainMenuView> {
const Icon(CupertinoIcons.person_2_fill),
],
),
onTap: () => _isDeletionModeEnabled
? _showDeleteSingleGamePopup(index)
: () async {
onTap: () async {
//ignore: unused_local_variable
final val = await Navigator.push(
context,
CupertinoPageRoute(
builder: (context) =>
ActiveGameView(
gameSession: Globals
.gameList[index]),
builder: (context) => ActiveGameView(
gameSession: Globals.gameList[index]),
),
);
setState(() {});
@@ -182,7 +158,7 @@ class _MainMenuViewState extends State<MainMenuView> {
),
),
),
));
);
}
/// Translates the game mode boolean into the corresponding String.
@@ -193,47 +169,16 @@ class _MainMenuViewState extends State<MainMenuView> {
}
/// Shows a confirmation dialog to delete all game sessions.
void _showDeleteAllGamesPopup() {
showCupertinoDialog(
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: const Text('Alle Spiele löschen?'),
content: const Text(
'Bist du sicher, dass du alle Spiele löschen möchtest? Diese Aktion kann nicht rückgängig gemacht werden.'),
actions: [
CupertinoDialogAction(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Abbrechen'),
),
CupertinoDialogAction(
onPressed: () {
setState(() {
_deleteAllGames();
_isDeletionModeEnabled = false;
});
Navigator.pop(context);
},
child: const Text('Löschen'),
),
],
);
},
);
}
/// Shows a confirmation dialog to delete all game sessions.
Future<bool> _showDeleteSingleGamePopup(int gameIndex) async {
final String title = Globals.gameList[gameIndex].gameTitle;
/// Returns true if the user confirms the deletion, false otherwise.
///
Future<bool> _showDeleteGamePopup(String gameTitle) async {
bool? shouldDelete = await showCupertinoDialog<bool>(
context: context,
builder: (context) {
return CupertinoAlertDialog(
title: const Text('Spiel löschen?'),
content: Text(
'Bist du sicher, dass du die Runde "$title" löschen möchtest? Diese Aktion kann nicht rückgängig gemacht werden.'),
'Bist du sicher, dass du die Runde "$gameTitle" löschen möchtest? Diese Aktion kann nicht rückgängig gemacht werden.'),
actions: [
CupertinoDialogAction(
onPressed: () {
@@ -250,17 +195,9 @@ class _MainMenuViewState extends State<MainMenuView> {
],
);
},
);
return shouldDelete ?? false;
} //
/// Deletes all game sessions.
/// This functions clears the global games lists and triggers a save to the
/// local storage. This overwrites the existing game data so that both the
/// local json file and the global variable are empty.
void _deleteAllGames() {
Globals.gameList.clear();
LocalStorageService.saveGameSessions();
) ??
false;
return shouldDelete;
}
/// Deletes a specific game session by its index.