mirror of
https://github.com/PranshulGG/WeatherMaster.git
synced 2026-10-22 11:02:53 -05:00
31 lines
739 B
Dart
31 lines
739 B
Dart
import 'package:flutter/material.dart';
|
|
|
|
class SnackUtil {
|
|
/// Shows a reusable SnackBar with optional action.
|
|
static void showSnackBar({
|
|
required BuildContext context,
|
|
required String message,
|
|
Duration duration = const Duration(seconds: 3),
|
|
String? actionLabel,
|
|
VoidCallback? onActionPressed,
|
|
}) {
|
|
|
|
final snackBar = SnackBar(
|
|
content: Text(
|
|
message,
|
|
),
|
|
duration: duration,
|
|
action: (actionLabel != null && onActionPressed != null)
|
|
? SnackBarAction(
|
|
label: actionLabel,
|
|
onPressed: onActionPressed,
|
|
)
|
|
: null,
|
|
);
|
|
|
|
ScaffoldMessenger.of(context)
|
|
..hideCurrentSnackBar()
|
|
..showSnackBar(snackBar);
|
|
}
|
|
}
|