From 2b528f09381b8b39c14b2e98aa84e0cdbcc2697d Mon Sep 17 00:00:00 2001 From: Edouard Marquez Date: Sat, 5 Aug 2023 23:17:01 +0200 Subject: [PATCH] Add some consistency between dialogs in the profile --- .../dialogs/smooth_alert_dialog.dart | 34 +++++++ .../user_preferences_contribute.dart | 78 ++++++++------- .../preferences/user_preferences_faq.dart | 96 ++++++++----------- 3 files changed, 114 insertions(+), 94 deletions(-) diff --git a/packages/smooth_app/lib/generic_lib/dialogs/smooth_alert_dialog.dart b/packages/smooth_app/lib/generic_lib/dialogs/smooth_alert_dialog.dart index 55a85f33982..540dd365435 100644 --- a/packages/smooth_app/lib/generic_lib/dialogs/smooth_alert_dialog.dart +++ b/packages/smooth_app/lib/generic_lib/dialogs/smooth_alert_dialog.dart @@ -497,6 +497,40 @@ class _SmoothActionFlatButton extends StatelessWidget { } } +/// A [Button] that can be displayed in the [body] of a [SmoothAlertDialog]. +class SmoothAlertContentButton extends StatelessWidget { + const SmoothAlertContentButton({ + required this.label, + required this.onPressed, + this.icon, + }); + + final String label; + final IconData? icon; + final VoidCallback onPressed; + + @override + Widget build(BuildContext context) { + return TextButton( + onPressed: onPressed, + child: FractionallySizedBox( + widthFactor: 0.8, + child: Row( + children: [ + Expanded( + child: Text(label), + ), + if (icon != null) + ExcludeSemantics( + child: Icon(icon), + ), + ], + ), + ), + ); + } +} + /// A custom dialog where you only have to pass a [title] and a [message]. /// By default an "OK" button will be show., but you can override it by passing /// a [positiveAction] and/or [negativeAction] diff --git a/packages/smooth_app/lib/pages/preferences/user_preferences_contribute.dart b/packages/smooth_app/lib/pages/preferences/user_preferences_contribute.dart index e96ad53ead0..5d7e482842d 100644 --- a/packages/smooth_app/lib/pages/preferences/user_preferences_contribute.dart +++ b/packages/smooth_app/lib/pages/preferences/user_preferences_contribute.dart @@ -114,14 +114,8 @@ class UserPreferencesContribute extends AbstractUserPreferences { ], ), positiveAction: SmoothActionButton( - text: appLocalizations.okay, - minWidth: 100, - onPressed: () => Navigator.pop(context), - ), - negativeAction: SmoothActionButton( text: AppLocalizations.of(context) .contribute_improve_ProductsToBeCompleted, - minWidth: 150, onPressed: () async { final LocalDatabase localDatabase = context.read(); @@ -136,8 +130,15 @@ class UserPreferencesContribute extends AbstractUserPreferences { ); }, ), + negativeAction: SmoothActionButton( + onPressed: () { + Navigator.of(context, rootNavigator: true).pop('dialog'); + }, + text: appLocalizations.close, + minWidth: 100, + ), actionsAxis: Axis.vertical, - actionsOrder: SmoothButtonsBarOrder.numerical, + actionsOrder: SmoothButtonsBarOrder.auto, ); }, ); @@ -155,34 +156,28 @@ class UserPreferencesContribute extends AbstractUserPreferences { const SizedBox(height: VERY_LARGE_SPACE), Text(appLocalizations.contribute_develop_text_2), const SizedBox(height: 10), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - TextButton( - onPressed: () => LaunchUrlHelper.launchURL( - 'https://slack.openfoodfacts.org/', false), - child: const Text( - 'Slack', - style: TextStyle(color: Colors.blue), - ), - ), - TextButton( - onPressed: () => LaunchUrlHelper.launchURL( - 'https://github.com/openfoodfacts', false), - child: const Text( - 'Github', - style: TextStyle(color: Colors.blue), - ), - ), - ], + SmoothAlertContentButton( + label: 'Slack', + icon: Icons.open_in_new, + onPressed: () => LaunchUrlHelper.launchURL( + 'https://slack.openfoodfacts.org/', false), + ), + const SizedBox(height: SMALL_SPACE), + SmoothAlertContentButton( + label: 'GitHub', + icon: Icons.open_in_new, + onPressed: () => LaunchUrlHelper.launchURL( + 'https://github.com/openfoodfacts', false), ), const SizedBox(height: 10), const _DevModeSetting(), ], ), - positiveAction: SmoothActionButton( - onPressed: () => Navigator.pop(context), - text: appLocalizations.okay, + negativeAction: SmoothActionButton( + onPressed: () { + Navigator.of(context, rootNavigator: true).pop('dialog'); + }, + text: appLocalizations.close, minWidth: 100, ), ); @@ -211,6 +206,15 @@ class UserPreferencesContribute extends AbstractUserPreferences { 'https://translate.openfoodfacts.org/', false), text: appLocalizations.contribute_translate_link_text, ), + negativeAction: SmoothActionButton( + onPressed: () { + Navigator.of(context, rootNavigator: true).pop('dialog'); + }, + text: appLocalizations.close, + minWidth: 100, + ), + actionsAxis: Axis.vertical, + actionsOrder: SmoothButtonsBarOrder.auto, ); }, ); @@ -338,20 +342,20 @@ class _ContributorsDialog extends StatelessWidget { }, ), positiveAction: SmoothActionButton( + onPressed: () => LaunchUrlHelper.launchURL( + 'https://github.com/openfoodfacts/smooth-app', false), + text: AppLocalizations.of(context).contribute, + minWidth: 150, + ), + negativeAction: SmoothActionButton( onPressed: () { Navigator.of(context, rootNavigator: true).pop('dialog'); }, text: appLocalizations.close, minWidth: 100, ), - negativeAction: SmoothActionButton( - onPressed: () => LaunchUrlHelper.launchURL( - 'https://github.com/openfoodfacts/smooth-app', false), - text: AppLocalizations.of(context).contribute, - minWidth: 150, - ), actionsAxis: Axis.vertical, - actionsOrder: SmoothButtonsBarOrder.numerical, + actionsOrder: SmoothButtonsBarOrder.auto, ); } } diff --git a/packages/smooth_app/lib/pages/preferences/user_preferences_faq.dart b/packages/smooth_app/lib/pages/preferences/user_preferences_faq.dart index 9d4e7d0d005..608f762859a 100644 --- a/packages/smooth_app/lib/pages/preferences/user_preferences_faq.dart +++ b/packages/smooth_app/lib/pages/preferences/user_preferences_faq.dart @@ -137,72 +137,54 @@ class UserPreferencesFaq extends AbstractUserPreferences { ), ], ), - Divider(color: themeData.colorScheme.onSurface), const SizedBox(height: VERY_LARGE_SPACE), SingleChildScrollView( - child: Column( - children: [ - Text(appLocalizations.whatIsOff), - const SizedBox(height: LARGE_SPACE), - IntrinsicHeight( - child: Row( - crossAxisAlignment: CrossAxisAlignment.stretch, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Expanded( - child: TextButton( - onPressed: () => LaunchUrlHelper.launchURL( - 'https://openfoodfacts.org/who-we-are', true), - child: Text( - appLocalizations.learnMore, - textAlign: TextAlign.center, - style: const TextStyle( - color: Colors.blue, - ), - ), - ), + child: IconTheme( + data: const IconThemeData(size: 16.0), + child: Column( + children: [ + FractionallySizedBox( + widthFactor: 0.9, + child: Text(appLocalizations.whatIsOff), + ), + const SizedBox(height: LARGE_SPACE), + SmoothAlertContentButton( + onPressed: () => LaunchUrlHelper.launchURL( + 'https://openfoodfacts.org/who-we-are', true), + label: appLocalizations.learnMore, + icon: Icons.open_in_new, + ), + const SizedBox(height: SMALL_SPACE), + SmoothAlertContentButton( + onPressed: () => LaunchUrlHelper.launchURL( + 'https://openfoodfacts.org/terms-of-', true), + label: appLocalizations.termsOfUse, + icon: Icons.open_in_new, + ), + const SizedBox(height: SMALL_SPACE), + SmoothAlertContentButton( + onPressed: () => showLicensePage( + context: context, + applicationName: packageInfo.appName, + applicationVersion: packageInfo.version, + applicationIcon: SvgPicture.asset( + logo, + height: MediaQuery.of(context).size.height * 0.1, ), - Expanded( - child: TextButton( - onPressed: () => LaunchUrlHelper.launchURL( - 'https://openfoodfacts.org/terms-of-use', - true), - child: Text( - appLocalizations.termsOfUse, - textAlign: TextAlign.center, - style: const TextStyle( - color: Colors.blue, - ), - ), - ), - ) - ], + ), + label: appLocalizations.licenses, + icon: Icons.info, ), - ), - ], + const SizedBox(height: SMALL_SPACE), + ], + ), ), ), ], ), - positiveAction: SmoothActionButton( - onPressed: () => Navigator.of(context, rootNavigator: true).pop(), - text: appLocalizations.okay, - ), negativeAction: SmoothActionButton( - onPressed: () async { - Navigator.of(context).pop(); - - showLicensePage( - context: context, - applicationName: packageInfo.appName, - applicationVersion: packageInfo.version, - applicationIcon: SvgPicture.asset( - logo, - height: MediaQuery.of(context).size.height * 0.1, - ), - ); - }, - text: appLocalizations.licenses, + onPressed: () => Navigator.of(context, rootNavigator: true).pop(), + text: appLocalizations.close, ), ); },