showSnackBar function
void
showSnackBar(
- BuildContext context,
- dynamic widget, {
- Duration? duration,
- double? containerHeight,
- SnackBarBehavior? behavior,
- String? label,
- TextStyle? textStyle,
- SnackBarAction? action,
Implementation
void showSnackBar(BuildContext context, dynamic widget,
{Duration? duration,
double? containerHeight,
SnackBarBehavior? behavior,
String? label,
TextStyle? textStyle,
SnackBarAction? action}) {
void Function()? close;
ScaffoldMessenger.maybeOf(context)?.clearSnackBars();
final snackbar = ScaffoldMessenger.maybeOf(context)?.showSnackBar(
SnackBar(
behavior: behavior != null
? behavior
: Scaffold.maybeOf(context) == null
? SnackBarBehavior.fixed
: Scaffold.of(context).hasFloatingActionButton
? SnackBarBehavior.fixed
: SnackBarBehavior.floating,
action: action == null
? action
: label == null
? null
: SnackBarAction(
label: "Dismiss",
onPressed: () {
if (close != null) {
close();
}
},
),
duration: duration != null
? duration
: const Duration(
seconds: 30,
),
content: widget.runtimeType == String
? Text(
widget.toString(),
style: textStyle,
)
: Column(
children: [
SizedBox(
width: width(context),
child: const Icon(Icons.drag_handle_rounded),
),
widget as Widget,
],
),
),
);
close = () {
snackbar!.close();
};
}