-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from enrique-lozano/feat/improve-confirm-dialog
Add icons in some confirmation dialogs
- Loading branch information
Showing
12 changed files
with
64 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,53 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:monekin/i18n/translations.g.dart'; | ||
|
||
/// Display a dialog with a title, a description and confirm/cancel buttons | ||
Future<bool?> showConfirmDialog( | ||
/// Display a dialog with a title, a description and confirm/cancel buttons. | ||
/// | ||
/// When the confirm dialogs is closed, it will return `true` or `false` when one of the actions | ||
/// button is pressed, and null if closed without tapping on any icon | ||
Future<bool?> confirmDialog( | ||
BuildContext context, { | ||
required String dialogTitle, | ||
required List<Widget> contentParagraphs, | ||
bool showCancelButton = false, | ||
String? confirmationText, | ||
IconData? icon, | ||
bool canPop = true, | ||
}) { | ||
final t = Translations.of(context); | ||
|
||
return showDialog<bool>( | ||
context: context, | ||
builder: (context) => AlertDialog.adaptive( | ||
title: Text(dialogTitle), | ||
content: SingleChildScrollView( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: contentParagraphs | ||
.expand((element) => [element, const SizedBox(height: 6)]) | ||
.toList(), | ||
barrierDismissible: canPop, | ||
builder: (context) => PopScope( | ||
canPop: canPop, | ||
child: AlertDialog.adaptive( | ||
title: Text(dialogTitle), | ||
icon: icon != null ? Icon(icon, size: 36) : null, | ||
content: SingleChildScrollView( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: contentParagraphs | ||
.expand((element) => [element, const SizedBox(height: 6)]) | ||
.toList(), | ||
), | ||
), | ||
), | ||
actions: [ | ||
if (showCancelButton) | ||
actions: [ | ||
if (showCancelButton) | ||
TextButton( | ||
child: Text(t.general.cancel), | ||
onPressed: () { | ||
Navigator.of(context, rootNavigator: true).pop(false); | ||
}, | ||
), | ||
TextButton( | ||
child: Text(t.general.cancel), | ||
child: Text(confirmationText ?? t.general.understood), | ||
onPressed: () { | ||
Navigator.of(context, rootNavigator: true).pop(false); | ||
Navigator.of(context, rootNavigator: true).pop(true); | ||
}, | ||
), | ||
TextButton( | ||
child: Text(confirmationText ?? t.general.understood), | ||
onPressed: () { | ||
Navigator.of(context, rootNavigator: true).pop(true); | ||
}, | ||
), | ||
], | ||
], | ||
), | ||
), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters