Removed old deletion way
This commit is contained in:
@@ -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() {
|
||||||
@@ -46,14 +45,10 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
icon: _isDeletionModeEnabled
|
icon: const Icon(CupertinoIcons.settings, size: 30)),
|
||||||
? const Icon(null)
|
|
||||||
: const Icon(CupertinoIcons.settings, size: 30)),
|
|
||||||
middle: const Text('Cabo Counter'),
|
middle: const Text('Cabo Counter'),
|
||||||
trailing: IconButton(
|
trailing: IconButton(
|
||||||
onPressed: () => _isDeletionModeEnabled
|
onPressed: () => {
|
||||||
? _showDeleteAllGamesPopup()
|
|
||||||
: {
|
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
@@ -61,9 +56,7 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
icon: _isDeletionModeEnabled
|
icon: const Icon(CupertinoIcons.add)),
|
||||||
? const Icon(CupertinoIcons.trash, size: 25)
|
|
||||||
: const Icon(CupertinoIcons.add)),
|
|
||||||
),
|
),
|
||||||
child: CupertinoPageScaffold(
|
child: CupertinoPageScaffold(
|
||||||
child: SafeArea(
|
child: SafeArea(
|
||||||
@@ -95,23 +88,7 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
: GestureDetector(
|
: ListView.builder(
|
||||||
onTap: () => {
|
|
||||||
if (_isDeletionModeEnabled)
|
|
||||||
{
|
|
||||||
setState(() {
|
|
||||||
_isDeletionModeEnabled = false;
|
|
||||||
}),
|
|
||||||
print('Deletion mode: $_isDeletionModeEnabled')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onLongPress: () => {
|
|
||||||
setState(() {
|
|
||||||
_isDeletionModeEnabled = true;
|
|
||||||
}),
|
|
||||||
print('Deletion mode: $_isDeletionModeEnabled')
|
|
||||||
},
|
|
||||||
child: ListView.builder(
|
|
||||||
itemCount: Globals.gameList.length,
|
itemCount: Globals.gameList.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final session = Globals.gameList[index];
|
final session = Globals.gameList[index];
|
||||||
@@ -128,15 +105,18 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
),
|
),
|
||||||
direction: DismissDirection.startToEnd,
|
direction: DismissDirection.startToEnd,
|
||||||
confirmDismiss: (direction) async {
|
confirmDismiss: (direction) async {
|
||||||
if (_isDeletionModeEnabled) return false;
|
final String gameTitle =
|
||||||
return await _showDeleteSingleGamePopup(index);
|
Globals.gameList[index].gameTitle;
|
||||||
|
return await _showDeleteGamePopup(gameTitle);
|
||||||
},
|
},
|
||||||
onDismissed: (direction) {
|
onDismissed: (direction) {
|
||||||
_deleteSpecificGame(index);
|
_deleteSpecificGame(index);
|
||||||
},
|
},
|
||||||
|
dismissThresholds: const {
|
||||||
|
DismissDirection.startToEnd: 0.6
|
||||||
|
},
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding:
|
padding: const EdgeInsets.symmetric(vertical: 10.0),
|
||||||
const EdgeInsets.symmetric(vertical: 10.0),
|
|
||||||
child: CupertinoListTile(
|
child: CupertinoListTile(
|
||||||
title: Text(session.gameTitle),
|
title: Text(session.gameTitle),
|
||||||
subtitle: session.isGameFinished == true
|
subtitle: session.isGameFinished == true
|
||||||
@@ -160,17 +140,13 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
const Icon(CupertinoIcons.person_2_fill),
|
const Icon(CupertinoIcons.person_2_fill),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
onTap: () => _isDeletionModeEnabled
|
onTap: () async {
|
||||||
? _showDeleteSingleGamePopup(index)
|
|
||||||
: () async {
|
|
||||||
//ignore: unused_local_variable
|
//ignore: unused_local_variable
|
||||||
final val = await Navigator.push(
|
final val = await Navigator.push(
|
||||||
context,
|
context,
|
||||||
CupertinoPageRoute(
|
CupertinoPageRoute(
|
||||||
builder: (context) =>
|
builder: (context) => ActiveGameView(
|
||||||
ActiveGameView(
|
gameSession: Globals.gameList[index]),
|
||||||
gameSession: Globals
|
|
||||||
.gameList[index]),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
@@ -182,7 +158,7 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
));
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translates the game mode boolean into the corresponding String.
|
/// 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.
|
/// 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: () {
|
||||||
@@ -250,17 +195,9 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
) ??
|
||||||
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.
|
||||||
|
|||||||
Reference in New Issue
Block a user