Changed popups because of unmounted context errors
This commit is contained in:
@@ -75,14 +75,12 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
icon: const Icon(CupertinoIcons.settings, size: 30)),
|
icon: const Icon(CupertinoIcons.settings, size: 30)),
|
||||||
middle: const Text('Cabo Counter'),
|
middle: const Text('Cabo Counter'),
|
||||||
trailing: IconButton(
|
trailing: IconButton(
|
||||||
onPressed: () => {
|
onPressed: () => Navigator.push(
|
||||||
Navigator.push(
|
context,
|
||||||
context,
|
CupertinoPageRoute(
|
||||||
CupertinoPageRoute(
|
builder: (context) => const CreateGameView(),
|
||||||
builder: (context) => const CreateGameView(),
|
),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
},
|
|
||||||
icon: const Icon(CupertinoIcons.add)),
|
icon: const Icon(CupertinoIcons.add)),
|
||||||
),
|
),
|
||||||
child: CupertinoPageScaffold(
|
child: CupertinoPageScaffold(
|
||||||
@@ -146,7 +144,7 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
final String gameTitle = gameManager
|
final String gameTitle = gameManager
|
||||||
.gameList[index].gameTitle;
|
.gameList[index].gameTitle;
|
||||||
return await _showDeleteGamePopup(
|
return await _showDeleteGamePopup(
|
||||||
gameTitle);
|
gameTitle, context);
|
||||||
},
|
},
|
||||||
onDismissed: (direction) {
|
onDismissed: (direction) {
|
||||||
gameManager
|
gameManager
|
||||||
@@ -261,50 +259,37 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Shows a Cupertino dialog with a title, content, and a list of actions.
|
|
||||||
Future<T?> _showCupertinoChoiceDialog<T>({
|
|
||||||
required String title,
|
|
||||||
required String content,
|
|
||||||
required List<({Widget content, VoidCallback onPressed})> actions,
|
|
||||||
}) {
|
|
||||||
return showCupertinoDialog<T>(
|
|
||||||
context: context,
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
return CupertinoAlertDialog(
|
|
||||||
title: Text(title),
|
|
||||||
content: Text(content),
|
|
||||||
actions: actions
|
|
||||||
.map((action) => CupertinoDialogAction(
|
|
||||||
onPressed: action.onPressed,
|
|
||||||
child: action.content,
|
|
||||||
))
|
|
||||||
.toList(),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Shows a confirmation dialog to delete all game sessions.
|
/// Shows a confirmation dialog to delete all game sessions.
|
||||||
/// Returns true if the user confirms the deletion, false otherwise.
|
/// Returns true if the user confirms the deletion, false otherwise.
|
||||||
/// [gameTitle] is the title of the game session to be deleted.
|
/// [gameTitle] is the title of the game session to be deleted.
|
||||||
Future<bool> _showDeleteGamePopup(String gameTitle) async {
|
Future<bool?> _showDeleteGamePopup(
|
||||||
return await _showCupertinoChoiceDialog<bool>(
|
String gameTitle, BuildContext context) async {
|
||||||
title: AppLocalizations.of(context).delete_game_title,
|
return await showCupertinoDialog<bool>(
|
||||||
content: AppLocalizations.of(context).delete_game_message(gameTitle),
|
context: context,
|
||||||
actions: [
|
builder: (BuildContext context) {
|
||||||
(
|
return CupertinoAlertDialog(
|
||||||
content: Text(AppLocalizations.of(context).delete,
|
title: Text(
|
||||||
style: const TextStyle(
|
AppLocalizations.of(context).delete_game_title,
|
||||||
color: CupertinoColors.destructiveRed,
|
),
|
||||||
fontWeight: FontWeight.bold,
|
content: Text(AppLocalizations.of(context)
|
||||||
)),
|
.delete_game_message(gameTitle)),
|
||||||
onPressed: () => Navigator.of(context).pop(true)
|
actions: [
|
||||||
),
|
CupertinoDialogAction(
|
||||||
(
|
child: Text(AppLocalizations.of(context).cancel),
|
||||||
content: Text(AppLocalizations.of(context).cancel),
|
onPressed: () {
|
||||||
onPressed: () => Navigator.of(context).pop(false)
|
Navigator.of(context).pop(false);
|
||||||
)
|
}),
|
||||||
],
|
CupertinoDialogAction(
|
||||||
|
isDestructiveAction: true,
|
||||||
|
isDefaultAction: true,
|
||||||
|
child: Text(
|
||||||
|
AppLocalizations.of(context).delete,
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop(true);
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
},
|
||||||
) ??
|
) ??
|
||||||
false;
|
false;
|
||||||
}
|
}
|
||||||
@@ -315,25 +300,32 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
/// - PRE_RATING_DIALOG_NO: User does not like the app and wants to provide feedback.
|
/// - PRE_RATING_DIALOG_NO: User does not like the app and wants to provide feedback.
|
||||||
/// - PRE_RATING_DIALOG_CANCEL: User cancels the dialog.
|
/// - PRE_RATING_DIALOG_CANCEL: User cancels the dialog.
|
||||||
Future<int> _showPreRatingDialog(BuildContext context) async {
|
Future<int> _showPreRatingDialog(BuildContext context) async {
|
||||||
return await _showCupertinoChoiceDialog<int>(
|
return await showCupertinoDialog<int>(
|
||||||
title: AppLocalizations.of(context).pre_rating_title,
|
context: context,
|
||||||
content: AppLocalizations.of(context).pre_rating_message,
|
builder: (BuildContext context) => CupertinoAlertDialog(
|
||||||
actions: [
|
title: Text(AppLocalizations.of(context).pre_rating_title),
|
||||||
(
|
content:
|
||||||
content: Text(AppLocalizations.of(context).yes),
|
Text(AppLocalizations.of(context).pre_rating_message),
|
||||||
onPressed: () => Navigator.of(context).pop(PRE_RATING_DIALOG_YES)
|
actions: [
|
||||||
),
|
CupertinoDialogAction(
|
||||||
(
|
onPressed: () =>
|
||||||
content: Text(AppLocalizations.of(context).no),
|
Navigator.of(context).pop(PRE_RATING_DIALOG_YES),
|
||||||
onPressed: () => Navigator.of(context).pop(PRE_RATING_DIALOG_NO)
|
isDefaultAction: true,
|
||||||
),
|
child: Text(AppLocalizations.of(context).yes),
|
||||||
(
|
),
|
||||||
content: Text(AppLocalizations.of(context).cancel),
|
CupertinoDialogAction(
|
||||||
onPressed: () =>
|
onPressed: () =>
|
||||||
Navigator.of(context).pop(PRE_RATING_DIALOG_CANCEL)
|
Navigator.of(context).pop(PRE_RATING_DIALOG_NO),
|
||||||
),
|
child: Text(AppLocalizations.of(context).no),
|
||||||
],
|
),
|
||||||
) ??
|
CupertinoDialogAction(
|
||||||
|
onPressed: () =>
|
||||||
|
Navigator.of(context).pop(PRE_RATING_DIALOG_CANCEL),
|
||||||
|
isDestructiveAction: true,
|
||||||
|
child: Text(AppLocalizations.of(context).cancel),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)) ??
|
||||||
PRE_RATING_DIALOG_CANCEL;
|
PRE_RATING_DIALOG_CANCEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,22 +334,26 @@ class _MainMenuViewState extends State<MainMenuView> {
|
|||||||
/// - BAD_RATING_DIALOG_EMAIL: User wants to send an email with feedback.
|
/// - BAD_RATING_DIALOG_EMAIL: User wants to send an email with feedback.
|
||||||
/// - BAD_RATING_DIALOG_CANCEL: User cancels the dialog.
|
/// - BAD_RATING_DIALOG_CANCEL: User cancels the dialog.
|
||||||
Future<int> _showBadRatingDialog(BuildContext context) async {
|
Future<int> _showBadRatingDialog(BuildContext context) async {
|
||||||
return await _showCupertinoChoiceDialog<int>(
|
return await showCupertinoDialog<int>(
|
||||||
title: AppLocalizations.of(context).bad_rating_title,
|
context: context,
|
||||||
content: AppLocalizations.of(context).bad_rating_message,
|
builder: (BuildContext context) => CupertinoAlertDialog(
|
||||||
actions: [
|
title: Text(AppLocalizations.of(context).bad_rating_title),
|
||||||
(
|
content:
|
||||||
content: Text(AppLocalizations.of(context).contact_email),
|
Text(AppLocalizations.of(context).bad_rating_message),
|
||||||
onPressed: () =>
|
actions: [
|
||||||
Navigator.of(context).pop(BAD_RATING_DIALOG_EMAIL)
|
CupertinoDialogAction(
|
||||||
),
|
isDefaultAction: true,
|
||||||
(
|
onPressed: () =>
|
||||||
content: Text(AppLocalizations.of(context).cancel),
|
Navigator.of(context).pop(BAD_RATING_DIALOG_EMAIL),
|
||||||
onPressed: () =>
|
child: Text(AppLocalizations.of(context).contact_email),
|
||||||
Navigator.of(context).pop(BAD_RATING_DIALOG_CANCEL)
|
),
|
||||||
),
|
CupertinoDialogAction(
|
||||||
],
|
isDestructiveAction: true,
|
||||||
) ??
|
onPressed: () =>
|
||||||
|
Navigator.of(context).pop(BAD_RATING_DIALOG_CANCEL),
|
||||||
|
child: Text(AppLocalizations.of(context).cancel))
|
||||||
|
],
|
||||||
|
)) ??
|
||||||
BAD_RATING_DIALOG_CANCEL;
|
BAD_RATING_DIALOG_CANCEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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.4.0+461
|
version: 0.4.0+467
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.5.4
|
sdk: ^3.5.4
|
||||||
|
|||||||
Reference in New Issue
Block a user