showBasicSnackBar function

void showBasicSnackBar({
  1. required BuildContext context,
  2. required String content,
  3. SnackBarType type = SnackBarType.warning,
  4. Duration? duration,
  5. VoidCallback? onVisible,
})

Implementation

void showBasicSnackBar({
  required BuildContext context,
  required String content,
  SnackBarType type = SnackBarType.warning,
  Duration? duration,
  VoidCallback? onVisible,
}) {
  ScaffoldMessenger.of(context).hideCurrentSnackBar(
    reason: SnackBarClosedReason.remove,
  );

  ScaffoldMessenger.of(context).showSnackBar(
    SnackBar(
      onVisible: onVisible,
      padding: EdgeInsets.zero,
      elevation: 1,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(6),
        side: BorderSide(
          color: type.color,
        ),
      ),
      duration: duration ?? const Duration(seconds: 3),
      content: ColoredBox(
        color: Theme.of(context).colorScheme.surface,
        child: Padding(
          padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 14),
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              IconTheme(
                data: IconThemeData(
                  color: type.color,
                  size: 24,
                ),
                child: Icon(
                  type.icon,
                ),
              ),
              const SizedBox(width: 8),
              Text(
                content,
                style: Theme.of(context).textTheme.bodyMedium,
              ),
            ],
          ),
        ),
      ),
      backgroundColor: Theme.of(context).colorScheme.surface,
      behavior: SnackBarBehavior.floating,
    ),
  );
}