import 'package:bot_toast/bot_toast.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; final class KtToastUtils { KtToastUtils._(); static CancelFunc showError(String msg) { return showToast( msg, icon: Icon(Icons.error, size: 13, color: Colors.black), ); } static CancelFunc showSuccess({String? placeholder}) { return BotToast.showCustomLoading( duration: const Duration(milliseconds: 1500), clickClose: true, backgroundColor: Colors.black38, toastBuilder: (cancelFunc) { return Container( padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 16), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(4), ), child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ Icon(Icons.check, size: 32, color: Color(0xFF55731B)), SizedBox(height: 16), Text( placeholder ?? 'Success', style: TextStyle( fontSize: 14, color: Color(0xFF55731B), fontWeight: FontWeight.w600, height: 1.2, ), ), ], ), ); }, ); } static CancelFunc showToast( String msg, { Widget? icon, bool autoClose = true, }) { return BotToast.showCustomText( crossPage: false, align: const Alignment(0, -0.8), duration: autoClose ? const Duration(milliseconds: 2000) : null, onlyOne: true, toastBuilder: (cancelFunc) { return Container( padding: EdgeInsets.symmetric(vertical: 18.w, horizontal: 24.w), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(8.w), ), child: Row( mainAxisSize: MainAxisSize.min, children: [ if (icon != null) icon, const SizedBox(width: 4), Flexible( child: Text( msg, style: TextStyle( color: const Color(0xFF55731B), fontSize: 16, fontWeight: FontWeight.w500, height: 0.75, ), overflow: TextOverflow.ellipsis, strutStyle: const StrutStyle( leading: 0, forceStrutHeight: true, ), // 让文字和图标对齐 ), ), ], ), ); }, ); } static CancelFunc showLoading({ Duration? duration, bool? clickClose, String? placeholder, Color? backgroundColor, }) { return BotToast.showCustomLoading( duration: duration, clickClose: clickClose ?? true, backgroundColor: backgroundColor ?? Colors.black38, toastBuilder: (cancelFunc) { return Container( padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 16), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(4), ), child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, mainAxisSize: MainAxisSize.min, children: [ SizedBox( width: 32, height: 32, child: SpinKitDoubleBounce(color: Color(0xFF55731B)), ), SizedBox(height: 16), Text( placeholder ?? "Loading...", style: TextStyle( fontSize: 14, color: Color(0xFF55731B), fontWeight: FontWeight.w600, height: 1.2, ), ), ], ), ); }, ); } }