BuildToastStyle typedef
BuildToastStyle =
Widget Function(BuildContext context, String msg)
create_user: zhengzaihong email:1096877329@qq.com create_date: 2021/12/23 create_time: 15:14 describe: Toast提示组件 - 支持多种显示模式、动画配置、队列管理 Enterprise-level Toast component - Supports multiple display modes, animation configuration, queue management
✨ 功能特性 / Features: • 🎨 灵活的样式配置 - 支持自定义颜色、圆角、阴影等 • 🎬 丰富的动画效果 - 淡入淡出、缩放动画可配置 • 📍 多种显示位置 - 顶部、中间、底部、自定义位置 • ⏱️ 队列管理 - 支持多个Toast排队显示 • 🔄 Loading状态 - 内置加载动画支持 • 🎯 状态提示 - 成功/失败状态样式 • 📱 响应式设计 - 自适应不同屏幕尺寸 • 🌐 全局配置 - 统一管理Toast样式
📖 使用示例 / Usage Examples:
// 示例1: 基础用法 - 显示简单提示
// Example 1: Basic usage - Show simple message
Toast.show('操作成功');
// 示例2: 自定义样式配置
// Example 2: Custom style configuration
Toast().initStyleConfig(
styleConfig: ToastStyleConfig(
margin: EdgeInsets.all(20),
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 15),
decoration: BoxDecoration(
color: Colors.black87,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 10,
offset: Offset(0, 4),
),
],
),
),
animationConfig: ToastAnimationConfig(
enableAnimation: true,
animationDuration: 300,
enableScaleAnimation: true,
),
);
// 示例3: 显示Loading加载动画
// Example 3: Show loading animation
Toast.showLoading(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
backgroundColor: Color(0x77000000),
barrierDismissible: false,
);
// 关闭Loading
Toast.closeLoading();
// 示例4: 显示状态提示(成功/失败)
// Example 4: Show status message (success/failure)
Toast.showStatus(
'保存成功',
status: true,
iconColorSuccess: Colors.green,
iconColorError: Colors.red,
);
// 示例5: 队列方式显示多个Toast
// Example 5: Show multiple toasts in queue
Toast.showQueueToast('消息1');
Toast.showQueueToast('消息2');
Toast.showQueueToast('消息3');
// 示例6: 自定义位置显示
// Example 6: Show at custom position
Toast.show(
'顶部提示',
position: ToastPosition.top,
showTime: 3000,
);
⚠️ 注意事项 / Notes: • 需要在MaterialApp中配置navigatorKey: Toast.navigatorState • 建议在应用启动时初始化全局样式配置 • Loading状态会阻止用户交互,使用时注意及时关闭 • 队列Toast会自动管理显示顺序,无需手动控制 • 自定义样式时注意保持视觉一致性
Implementation
typedef BuildToastStyle = Widget Function(BuildContext context, String msg);