showSnackBar function

void showSnackBar(
  1. BuildContext context,
  2. dynamic widget, {
  3. Duration? duration,
  4. double? containerHeight,
  5. SnackBarBehavior? behavior,
  6. String? label,
  7. TextStyle? textStyle,
  8. 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();
  };
}