FDencendToast class

Flutter纯Dart实现的Toast组件

与原生Toast不同,这个实现在Dart端运行,不依赖原生平台API 可以在所有Flutter平台上工作,包括桌面平台

架构特点:

  • 使用Flutter的Overlay系统创建和管理Toast
  • 实现队列机制确保多个Toast按序显示
  • 使用动画控制器管理淡入淡出效果
  • 支持完全自定义的Widget作为内容
  • 采用单例模式简化API使用

使用示例:

// 初始化(通常在MaterialApp或StatefulWidget中)
final fDencendToast = FDencendToast().init(context);

// 显示自定义Toast
fDencendToast.showToast(
  child: Container(
    padding: EdgeInsets.all(16),
    decoration: BoxDecoration(
      color: Colors.black54,
      borderRadius: BorderRadius.circular(8),
    ),
    child: Text('自定义Toast', style: TextStyle(color: Colors.white)),
  ),
);

优势:

  1. 跨平台一致性:在所有Flutter支持的平台提供相同的体验
  2. 高度可定制:支持任意Widget作为Toast内容
  3. 动画系统:平滑的淡入淡出效果
  4. 队列管理:多个Toast自动按序显示
  5. 响应式设计:自动适应键盘和屏幕尺寸变化

Constructors

FDencendToast()
主构造函数,返回单例实例
factory

Properties

context BuildContext?
用于显示Overlay的BuildContext
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

init(BuildContext context) FDencendToast
初始化方法,设置BuildContext
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeCustomDencendToast() → void
移除当前显示的Toast
removeQueuedCustomDencendToasts() → void
清空所有待显示的Toast
showToast({required Widget child, PositionedDencendToastBuilder? positionedDencendToastBuilder, Duration toastDuration = const Duration(seconds: 2), DencendToastGravity? gravity, Duration fadeDuration = const Duration(milliseconds: 350), bool ignorePointer = false, bool isDismissible = false}) → void
显示自定义Toast
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited