From 1ab3940e6abe744416f85a7351fe142f841aaf9a Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 24 Dec 2022 22:56:27 +1100 Subject: [PATCH] Notification fixes (#240) * Show snack bar for shorter duration if no associated action * Dismiss snack bars with tap * Upate release notes --- assets/release_notes.md | 2 +- lib/widget/snacks.dart | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/assets/release_notes.md b/assets/release_notes.md index cecb00f5..69f1c693 100644 --- a/assets/release_notes.md +++ b/assets/release_notes.md @@ -6,9 +6,9 @@ - Support custom icons for part category - Support custom icons for stock location +- Adjustments to notification messages - Updated translations - ### 0.9.1 - December 2022 --- diff --git a/lib/widget/snacks.dart b/lib/widget/snacks.dart index 1b316f3d..f9414435 100644 --- a/lib/widget/snacks.dart +++ b/lib/widget/snacks.dart @@ -45,15 +45,6 @@ void showSnackIcon(String text, {IconData? icon, Function()? onAction, bool? suc String _action = actionText ?? L10().details; - SnackBarAction? action; - - if (onAction != null) { - action = SnackBarAction( - label: _action, - onPressed: onAction, - ); - } - List childs = [ Text(text), Spacer(), @@ -64,11 +55,24 @@ void showSnackIcon(String text, {IconData? icon, Function()? onAction, bool? suc } OneContext().showSnackBar(builder: (context) => SnackBar( - content: Row( + content: GestureDetector( + child: Row( children: childs + ), + onTap: () { + ScaffoldMessenger.of(context!).hideCurrentSnackBar(); + }, ), backgroundColor: backgroundColor, - action: action + action: onAction == null ? null : SnackBarAction( + label: _action, + onPressed: () { + // Immediately dismiss the notification + ScaffoldMessenger.of(context!).hideCurrentSnackBar(); + onAction(); + } + ), + duration: Duration(seconds: onAction == null ? 1 : 2), ) );