withIcon static method

void withIcon({
  1. required BuildContext context,
  2. required String text,
  3. required IconData icon,
  4. required Color iconColor,
  5. required Color color,
  6. required Color textColor,
  7. double width = 300,
  8. Duration duration = const Duration(milliseconds: 1200),
})

A floating toast with a leading icon.

  • text The message to display.
  • icon The icon shown to the left of the text.
  • iconColor Color of the icon.
  • color Background color.
  • textColor Color of the message text.
  • width Width of the snackbar. Defaults to 300.
  • duration How long the toast is visible. Defaults to 1200 ms.

Implementation

static void withIcon({
  required BuildContext context,
  required String text,
  required IconData icon,
  required Color iconColor,
  required Color color,
  required Color textColor,
  double width = 300,
  Duration duration = const Duration(milliseconds: 1200),
}) {
  _show(
    context,
    SnackBar(
      clipBehavior: Clip.antiAliasWithSaveLayer,
      elevation: 0.5,
      shape: const OutlineInputBorder(borderSide: BorderSide.none),
      width: width,
      behavior: SnackBarBehavior.floating,
      duration: duration,
      backgroundColor: color,
      content: Row(
        children: [
          Container(
            height: 32,
            width: 32,
            decoration: BoxDecoration(
              color: color.withAlpha(60),
              borderRadius: BorderRadius.circular(6),
            ),
            child: Icon(icon, size: 20, color: iconColor),
          ),
          const SizedBox(width: 12),
          Expanded(
            child: Text(text, style: TextStyle(color: textColor)),
          ),
        ],
      ),
    ),
  );
}