showToastSuccess function

void showToastSuccess({
  1. required String message,
  2. required BuildContext context,
  3. Color? backgroundColor,
  4. bool showButton = false,
  5. ToastGravity? gravity,
  6. Duration? duration,
  7. EdgeInsetsGeometry? containerPadding,
  8. Decoration? containerDecoration,
  9. String? buttonText,
})

Implementation

void showToastSuccess(
    {required String message,
    required BuildContext context,
    Color? backgroundColor,
    bool showButton = false,
    ToastGravity? gravity,
    Duration? duration,
    EdgeInsetsGeometry? containerPadding,
    Decoration? containerDecoration,
    String? buttonText}) {
  FToast fToast;
  fToast = FToast();
  fToast.init(context);
  Widget toast = Container(
    padding: containerPadding ?? const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
    decoration: containerDecoration ??
        BoxDecoration(
          borderRadius: BorderRadius.circular(25.0),
          color: backgroundColor ?? Colors.green.shade300,
        ),
    child: Row(
      mainAxisSize: MainAxisSize.min,
      children: [
        Expanded(
            child: Text(
          message,
          style: const TextStyle(color: Colors.white),
        )),
        if (showButton)
          TextButton(
            onPressed: () {
              fToast.removeCustomToast();
            },
            style: TextButton.styleFrom(foregroundColor: Colors.white),
            child: Text(buttonText ?? "OK"),
          )
      ],
    ),
  );
  fToast.removeCustomToast();
  fToast.showToast(
    child: toast,
    gravity: gravity ?? ToastGravity.BOTTOM,
    toastDuration: duration ?? const Duration(seconds: 5),
  );
}