From f8162fd7383abc75bdfb3b1e523b2475b875d8a5 Mon Sep 17 00:00:00 2001 From: Edouard Marquez Date: Sat, 18 Jan 2025 22:50:58 +0100 Subject: [PATCH] Snackbar action button with a different background --- .../generic_lib/widgets/smooth_snackbar.dart | 27 ++++++++++++++++++- .../product/common/product_list_page.dart | 2 -- .../smooth_app/lib/themes/smooth_theme.dart | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/smooth_app/lib/generic_lib/widgets/smooth_snackbar.dart b/packages/smooth_app/lib/generic_lib/widgets/smooth_snackbar.dart index 1126030ad1a..b7652925c23 100644 --- a/packages/smooth_app/lib/generic_lib/widgets/smooth_snackbar.dart +++ b/packages/smooth_app/lib/generic_lib/widgets/smooth_snackbar.dart @@ -82,7 +82,7 @@ class SmoothFloatingSnackbar extends SnackBar { super.width, super.shape, super.hitTestBehavior, - super.action, + SnackBarAction? action, super.actionOverflowThreshold, super.showCloseIcon, super.closeIconColor, @@ -101,6 +101,10 @@ class SmoothFloatingSnackbar extends SnackBar { behavior: SnackBarBehavior.floating, backgroundColor: context.extension().error, + action: action?.copyWith( + backgroundColor: Colors.white38, + textColor: Colors.white, + ), content: Row( children: [ ExcludeSemantics( @@ -139,3 +143,24 @@ class SmoothFloatingSnackbar extends SnackBar { ), ); } + +extension SnackBarActionExtension on SnackBarAction { + SnackBarAction copyWith({ + String? label, + VoidCallback? onPressed, + Color? textColor, + Color? disabledTextColor, + Color? backgroundColor, + Color? disabledBackgroundColor, + }) { + return SnackBarAction( + textColor: textColor ?? this.textColor, + disabledTextColor: disabledTextColor ?? this.disabledTextColor, + backgroundColor: backgroundColor ?? this.backgroundColor, + disabledBackgroundColor: + disabledBackgroundColor ?? this.disabledBackgroundColor, + label: label ?? this.label, + onPressed: onPressed ?? this.onPressed, + ); + } +} diff --git a/packages/smooth_app/lib/pages/product/common/product_list_page.dart b/packages/smooth_app/lib/pages/product/common/product_list_page.dart index 7f0d8360541..474bc181f5d 100644 --- a/packages/smooth_app/lib/pages/product/common/product_list_page.dart +++ b/packages/smooth_app/lib/pages/product/common/product_list_page.dart @@ -417,11 +417,9 @@ class _ProductListPageState extends State ? appLocalizations.product_removed_list : appLocalizations.product_could_not_remove, ), - duration: SnackBarDuration.medium, action: !removed ? null : SnackBarAction( - textColor: PRIMARY_BLUE_COLOR, label: appLocalizations.undo, onPressed: () async { barcodes.insert(index, barcode); diff --git a/packages/smooth_app/lib/themes/smooth_theme.dart b/packages/smooth_app/lib/themes/smooth_theme.dart index f64c7904ed8..5390ede6fac 100644 --- a/packages/smooth_app/lib/themes/smooth_theme.dart +++ b/packages/smooth_app/lib/themes/smooth_theme.dart @@ -100,6 +100,7 @@ class SmoothTheme { fontWeight: FontWeight.w500, ), actionTextColor: Colors.white, + actionBackgroundColor: smoothExtension.primaryDark, backgroundColor: smoothExtension.primaryBlack, ), bannerTheme: MaterialBannerThemeData(