toast method

void toast(
  1. BuildContext context, {
  2. String? title,
  3. String? buttonLabel,
  4. dynamic onPressed()?,
  5. Color? buttonTheme,
  6. Color? theme,
})

Shows a toast notification with the provided title, buttonLabel, onPressed, buttonTheme, and theme.

context is the BuildContext to display the toast. title is the message to display in the toast. buttonLabel is the label of the action button in the toast. onPressed is the callback function to execute when the button is pressed. buttonTheme is the color of the button label. theme is the background color of the toast.

Implementation

void toast(
  BuildContext context, {
  String? title,
  String? buttonLabel,
  Function()? onPressed,
  Color? buttonTheme,
  Color? theme,
}) {
  ScaffoldMessenger.of(context).showSnackBar(
    SnackBar(
      content: Text(title ?? ''),
      backgroundColor: theme ?? Colors.green,
      action: SnackBarAction(
        label: buttonLabel ?? '',
        textColor: buttonTheme ?? Colors.black,
        onPressed: onPressed ?? () {},
      ),
    ),
  );
}