Toasta
简单、流畅、优雅的 Flutter 平台通用 Toast 库。受 iOS 启发。
Github 仓库
| iOS | Android |
|---|---|
![]() |
![]() |
Web 演示
如何使用
步骤 1:添加到 pubspec.yaml
flutter pub add toasta
步骤 2:将您的 MaterialApp 包裹在 ToastaContainer 中
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ToastaContainer( // Wrap your app by ToastaContainer
child: MaterialApp(
...
),
);
}
}
步骤 3:开始使用
final toast = Toast(title: "Hello World", subtitle: "This is Toasta");
Toasta(context).toast(toast);
| 属性 | 描述 | 默认值 |
|---|---|---|
height double |
Toast 的高度 | 56 |
width double |
Toast 的宽度 | 屏幕宽度的 70% |
darkMode bool |
深色模式 | 假 |
fadeInSubtitle bool |
副标题的淡入动画 | 假 |
title String Widget |
Toast 的上半部分,您可以传递 String 或 Widget 来自定义 | 空 |
subtitle String Widget |
Toast 的下半部分,您可以传递 String 或 Widget 来自定义 | 空 |
leading Widget |
自定义 Toast 的领先部分 | 空 |
trailing Widget |
自定义 Toast 的尾随部分 | 空 |
onTap Function |
点击 Toast 的回调 | 空 |
onAppear Function |
Toast 出现后的回调 | 空 |
onExit Function |
Toast 消失后的回调 | 空 |
status Enum |
您可以传递 ToastStatus success failed warning info |
空 |
backgroundColor Color |
自定义背景颜色 | 空 |
duration Duration |
Toast 的持续时间 | Duration(seconds: 3) |
borderRadius BorderRadius |
Toast 的圆角 | BorderRadius.all(Radius.circular(25.0)) |
支持
欢迎提出功能建议、报告 Bug 或自定义属性。


