showToast function

void showToast(
  1. String msg, {
  2. ToastType type = ToastType.info,
  3. ToastPosition? position,
  4. Duration? duration,
})

Implementation

void showToast(
    String msg, {
      ToastType type = ToastType.info,
      ok.ToastPosition? position,
      Duration? duration,
    }) {
  final config = _getToastConfig(type);
  final toastId = _nextToastId++;

  // Calculate offset based on existing toasts
  final offset = _activeToasts.length * 72.0; // 72px per toast (56 height + 16 gap)

  final future = ok.showToastWidget(
    Padding(
      padding: EdgeInsets.only(bottom: 32 + offset, right: 24),
      child: Container(
        constraints: const BoxConstraints(
          minWidth: 280,
          maxWidth: 420,
        ),
        decoration: BoxDecoration(
          color: config.backgroundColor,
          borderRadius: BorderRadius.circular(12),
          boxShadow: [
            BoxShadow(
              color: Colors.black.withOpacity(0.15),
              blurRadius: 12,
              offset: const Offset(0, 4),
              spreadRadius: 0,
            ),
          ],
          border: Border.all(
            color: config.iconColor.withOpacity(0.2),
            width: 1,
          ),
        ),
        child: IntrinsicHeight(
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            mainAxisSize: MainAxisSize.min,
            children: [
              // Colored side bar
              Container(
                width: 4,
                decoration: BoxDecoration(
                  color: config.iconColor,
                  borderRadius: const BorderRadius.only(
                    topLeft: Radius.circular(12),
                    bottomLeft: Radius.circular(12),
                  ),
                ),
              ),

              const SizedBox(width: 12),

              // Icon
              Container(
                padding: const EdgeInsets.all(8),
                child: Icon(
                  config.icon,
                  color: config.iconColor,
                  size: 20,
                ),
              ),

              const SizedBox(width: 12),

              // Message
              Flexible(
                child: Padding(
                  padding: const EdgeInsets.symmetric(vertical: 16),
                  child: Text(
                    msg,
                    style: TextStyle(
                      color: config.textColor,
                      fontSize: 14,
                      fontWeight: FontWeight.w500,
                      height: 1.4,
                    ),
                  ),
                ),
              ),

              const SizedBox(width: 12),
            ],
          ),
        ),
      ),
    ),
    duration: duration ?? const Duration(seconds: 3),
    position: position ?? ok.ToastPosition(align: Alignment.bottomRight),
    dismissOtherToast: false,
  );

  // Track this toast
  final entry = _ToastEntry(toastId, future);
  _activeToasts.add(entry);

  // Remove from tracking when done
  Future.delayed(duration ?? const Duration(seconds: 3), () {
    _activeToasts.removeWhere((e) => e.id == toastId);
  });
}