Skip to content

Latest commit

 

History

History
124 lines (111 loc) · 4.13 KB

weui_toast.md

File metadata and controls

124 lines (111 loc) · 4.13 KB

showWeuiToast

仿Weui的Toast效果

VoidCallback showWeuiToast({
  @required BuildContext context,
  @required Widget message,
  @required Widget icon,
  bool stopEvent = false,
  Alignment alignment,
  bool backButtonClose})
Param Type Default Description
[context] BuildContext 上下文
[message] Widget 提示消息
[icon] Widget 图标
[stopEvent] bool false 阻止父页面事件触发
[alignment] Alignment 默认是居中偏上 Toast的位置
[backButtonClose] bool 安卓返回按钮是否关闭Toast

返回参数:VoidCallback,用于关闭Toast

showWeuiSuccessToast

仿Weui的SuccessToast效果

Future showWeuiSuccessToast({
  @required BuildContext context,
  Widget message,
  bool stopEvent,
  bool backButtonClose,
  Alignment alignment,
  Duration closeDuration
  })
Param Type Default Description
[context] BuildContext 上下文
[alignment] Alignment 默认是居中偏上 Toast的位置
[message] Widget 成功 提示消息
[stopEvent] bool false 阻止父页面事件触发
[closeDuration] Duration 3s 关闭时间
[backButtonClose] bool true 安卓返回按钮是否关闭Toast

返回参数:Future dart 异步操作,代表Toast已关闭

showWeuiLoadingToast

仿Weui的LoadingToast效果

VoidCallback showWeuiToast({
  @required BuildContext context,
  Widget message,
  stopEvent = true,
  bool backButtonClose,
  Alignment alignment
  })
Param Type Default Description
[context] BuildContext 上下文
[message] Widget 提示消息
[stopEvent] bool true 阻止父页面事件触发
[backButtonClose] bool false 安卓返回按钮是否关闭Toast
[alignment] Alignment 默认是居中偏上 Toast的位置

返回参数:VoidCallback,用于关闭Toast

WeuiToastConfigData

设置默认Toast效果

const WeuiToastConfigData({this.successText = '成功',
        this.successDuration =  const Duration(seconds: 3),
        this.successBackButtonClose = true,
        this.loadingText = '加载中',
        this.loadingBackButtonClose = false,
        this.toastAlignment = const Alignment(0.0, -0.2)});
Param Type Default Description
[successText] String 成功 成功提示消息
[successDuration] Duration 3s 成功Toast关闭事件
[successBackButtonClose] bool true 成功安卓返回按钮是否关闭Toast
[loadingText] String 加载中 加载中提示消息
[loadingBackButtonClose] false true 加载中安卓返回按钮是否关闭Toast
[alignment] Alignment 默认是居中偏上 Toast的位置

WeuiToastConfig

设置默认Toast效果 配合WeuiToastConfigData使用

WeuiToastConfig({Widget child,this.data})
Param Type Default Description
[child] Widget Widget
[data] WeuiToastConfigData Toast配置数据
在Widget中添加了WeuiToastConfig,然后子Widget的context就可以应用到效果了
例如:
main.dart
class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return WeuiToastConfig( // --关键代码
      data: WeuiToastConfigData( // --关键代码
        successText: '测试ConfigData' // --关键代码
      ), // --关键代码
      child:MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
          primarySwatch: Colors.blue
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page')
    ));
  }
}

代表全局默认配置