add durations to snackbars

This commit is contained in:
Fabian Freund
2025-10-30 07:00:21 +01:00
parent 3955859e5b
commit 73a32349e0
+4
View File
@@ -61,6 +61,7 @@ void showTabOpenedMessage(
BuildContext context, { BuildContext context, {
String? tabName, String? tabName,
void Function()? onShow, void Function()? onShow,
Duration duration = const Duration(seconds: 3),
}) { }) {
final message = switch (tabName.whenNotEmpty) { final message = switch (tabName.whenNotEmpty) {
String() => "New tab '$tabName' opened in background", String() => "New tab '$tabName' opened in background",
@@ -72,6 +73,7 @@ void showTabOpenedMessage(
action: onShow.mapNotNull( action: onShow.mapNotNull(
(onPressed) => SnackBarAction(label: 'Show', onPressed: onPressed), (onPressed) => SnackBarAction(label: 'Show', onPressed: onPressed),
), ),
duration: duration,
); );
ScaffoldMessenger.of(context).showSnackBar(snackBar); ScaffoldMessenger.of(context).showSnackBar(snackBar);
@@ -106,6 +108,7 @@ void showTabSwitchMessage(
BuildContext context, { BuildContext context, {
String? tabName, String? tabName,
void Function()? onSwitch, void Function()? onSwitch,
Duration duration = const Duration(seconds: 3),
}) { }) {
ScaffoldMessenger.of(context).clearSnackBars(); ScaffoldMessenger.of(context).clearSnackBars();
@@ -119,6 +122,7 @@ void showTabSwitchMessage(
action: onSwitch.mapNotNull( action: onSwitch.mapNotNull(
(onPressed) => SnackBarAction(label: 'Switch', onPressed: onPressed), (onPressed) => SnackBarAction(label: 'Switch', onPressed: onPressed),
), ),
duration: duration,
); );
ScaffoldMessenger.of(context).showSnackBar(snackBar); ScaffoldMessenger.of(context).showSnackBar(snackBar);