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> { class _MainMenuViewState extends State<MainMenuView> {
bool _isLoading = true; bool _isLoading = true;
bool _isDeletionModeEnabled = false;
@override @override
initState() { initState() {
@@ -35,154 +34,131 @@ class _MainMenuViewState extends State<MainMenuView> {
LocalStorageService.loadGameSessions(); LocalStorageService.loadGameSessions();
return CupertinoPageScaffold( return CupertinoPageScaffold(
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
navigationBar: CupertinoNavigationBar( navigationBar: CupertinoNavigationBar(
leading: IconButton( leading: IconButton(
onPressed: () { onPressed: () {
Navigator.push( Navigator.push(
context, context,
CupertinoPageRoute( CupertinoPageRoute(
builder: (context) => const SettingsView(), builder: (context) => const SettingsView(),
), ),
); );
}, },
icon: _isDeletionModeEnabled icon: const Icon(CupertinoIcons.settings, size: 30)),
? const Icon(null) middle: const Text('Cabo Counter'),
: const Icon(CupertinoIcons.settings, size: 30)), trailing: IconButton(
middle: const Text('Cabo Counter'), onPressed: () => {
trailing: IconButton( Navigator.push(
onPressed: () => _isDeletionModeEnabled context,
? _showDeleteAllGamesPopup() CupertinoPageRoute(
: { builder: (context) => const CreateGame(),
Navigator.push( ),
context, )
CupertinoPageRoute( },
builder: (context) => const CreateGame(), icon: const Icon(CupertinoIcons.add)),
),
child: CupertinoPageScaffold(
child: SafeArea(
child: _isLoading
? const Center(child: CupertinoActivityIndicator())
: Globals.gameList.isEmpty
? Column(
mainAxisAlignment:
MainAxisAlignment.center, // Oben ausrichten
children: [
const SizedBox(height: 30), // Abstand von oben
Center(
child: GestureDetector(
onTap: () => setState(() {}),
child: Icon(
CupertinoIcons.plus,
size: 60,
color: CustomTheme.primaryColor,
),
)),
const SizedBox(height: 10), // Abstand von oben
const Padding(
padding: EdgeInsets.symmetric(horizontal: 70),
child: Text(
'Ganz schön leer hier...\nFüge über den Button oben rechts eine neue Runde hinzu.',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 16),
),
), ),
) ],
}, )
icon: _isDeletionModeEnabled : ListView.builder(
? const Icon(CupertinoIcons.trash, size: 25) itemCount: Globals.gameList.length,
: const Icon(CupertinoIcons.add)), itemBuilder: (context, index) {
), final session = Globals.gameList[index];
child: CupertinoPageScaffold( return Dismissible(
child: SafeArea( key: Key(session.gameTitle),
child: _isLoading background: Container(
? const Center(child: CupertinoActivityIndicator()) color: CupertinoColors.destructiveRed,
: Globals.gameList.isEmpty alignment: Alignment.centerLeft,
? Column( padding: const EdgeInsets.only(left: 20.0),
mainAxisAlignment: child: const Icon(
MainAxisAlignment.center, // Oben ausrichten CupertinoIcons.delete,
children: [ color: CupertinoColors.white,
const SizedBox(height: 30), // Abstand von oben
Center(
child: GestureDetector(
onTap: () => setState(() {}),
child: Icon(
CupertinoIcons.plus,
size: 60,
color: CustomTheme.primaryColor,
),
)),
const SizedBox(height: 10), // Abstand von oben
const Padding(
padding: EdgeInsets.symmetric(horizontal: 70),
child: Text(
'Ganz schön leer hier...\nFüge über den Button oben rechts eine neue Runde hinzu.',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 16),
), ),
), ),
], direction: DismissDirection.startToEnd,
) confirmDismiss: (direction) async {
: GestureDetector( final String gameTitle =
onTap: () => { Globals.gameList[index].gameTitle;
if (_isDeletionModeEnabled) return await _showDeleteGamePopup(gameTitle);
{
setState(() {
_isDeletionModeEnabled = false;
}),
print('Deletion mode: $_isDeletionModeEnabled')
}
},
onLongPress: () => {
setState(() {
_isDeletionModeEnabled = true;
}),
print('Deletion mode: $_isDeletionModeEnabled')
},
child: ListView.builder(
itemCount: Globals.gameList.length,
itemBuilder: (context, index) {
final session = Globals.gameList[index];
return Dismissible(
key: Key(session.gameTitle),
background: Container(
color: CupertinoColors.destructiveRed,
alignment: Alignment.centerLeft,
padding: const EdgeInsets.only(left: 20.0),
child: const Icon(
CupertinoIcons.delete,
color: CupertinoColors.white,
),
),
direction: DismissDirection.startToEnd,
confirmDismiss: (direction) async {
if (_isDeletionModeEnabled) return false;
return await _showDeleteSingleGamePopup(index);
},
onDismissed: (direction) {
_deleteSpecificGame(index);
},
child: Padding(
padding:
const EdgeInsets.symmetric(vertical: 10.0),
child: CupertinoListTile(
title: Text(session.gameTitle),
subtitle: session.isGameFinished == true
? Text(
'\u{1F947} ${session.winner}',
style: const TextStyle(fontSize: 14),
)
: Text(
'Modus: ${_translateGameMode(session.isPointsLimitEnabled)}',
style: const TextStyle(fontSize: 14),
),
trailing: Row(
children: [
Text('${session.roundNumber}'),
const SizedBox(width: 3),
const Icon(CupertinoIcons
.arrow_2_circlepath_circle_fill),
const SizedBox(width: 15),
Text('${session.players.length}'),
const SizedBox(width: 3),
const Icon(CupertinoIcons.person_2_fill),
],
),
onTap: () => _isDeletionModeEnabled
? _showDeleteSingleGamePopup(index)
: () async {
//ignore: unused_local_variable
final val = await Navigator.push(
context,
CupertinoPageRoute(
builder: (context) =>
ActiveGameView(
gameSession: Globals
.gameList[index]),
),
);
setState(() {});
},
),
),
);
}, },
), onDismissed: (direction) {
), _deleteSpecificGame(index);
), },
)); dismissThresholds: const {
DismissDirection.startToEnd: 0.6
},
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0),
child: CupertinoListTile(
title: Text(session.gameTitle),
subtitle: session.isGameFinished == true
? Text(
'\u{1F947} ${session.winner}',
style: const TextStyle(fontSize: 14),
)
: Text(
'Modus: ${_translateGameMode(session.isPointsLimitEnabled)}',
style: const TextStyle(fontSize: 14),
),
trailing: Row(
children: [
Text('${session.roundNumber}'),
const SizedBox(width: 3),
const Icon(CupertinoIcons
.arrow_2_circlepath_circle_fill),
const SizedBox(width: 15),
Text('${session.players.length}'),
const SizedBox(width: 3),
const Icon(CupertinoIcons.person_2_fill),
],
),
onTap: () async {
//ignore: unused_local_variable
final val = await Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => ActiveGameView(
gameSession: Globals.gameList[index]),
),
);
setState(() {});
},
),
),
);
},
),
),
),
);
} }
/// Translates the game mode boolean into the corresponding String. /// Translates the game mode boolean into the corresponding String.
@@ -193,74 +169,35 @@ class _MainMenuViewState extends State<MainMenuView> {
} }
/// Shows a confirmation dialog to delete all game sessions. /// Shows a confirmation dialog to delete all game sessions.
void _showDeleteAllGamesPopup() { /// Returns true if the user confirms the deletion, false otherwise.
showCupertinoDialog( ///
context: context, Future<bool> _showDeleteGamePopup(String gameTitle) async {
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;
bool? shouldDelete = await showCupertinoDialog<bool>( bool? shouldDelete = await showCupertinoDialog<bool>(
context: context, context: context,
builder: (context) { builder: (context) {
return CupertinoAlertDialog( return CupertinoAlertDialog(
title: const Text('Spiel löschen?'), title: const Text('Spiel löschen?'),
content: Text( 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: [ actions: [
CupertinoDialogAction( CupertinoDialogAction(
onPressed: () { onPressed: () {
Navigator.pop(context, false); Navigator.pop(context, false);
}, },
child: const Text('Abbrechen'), child: const Text('Abbrechen'),
), ),
CupertinoDialogAction( CupertinoDialogAction(
onPressed: () { onPressed: () {
Navigator.pop(context, true); Navigator.pop(context, true);
}, },
child: const Text('Löschen'), child: const Text('Löschen'),
), ),
], ],
); );
}, },
); ) ??
return shouldDelete ?? false; false;
} // return shouldDelete;
/// 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();
} }
/// Deletes a specific game session by its index. /// Deletes a specific game session by its index.