flutter_styled_toast

一个风格化的 Toast Flutter 包。您可以高度自定义 Toast。通过一系列动画美化 Toast,使其更美观。

演示

SlideFromLeftAnim

入门

dependencies:
  flutter_styled_toast: ^1.2.1
import 'package:flutter_styled_toast/flutter_styled_toast.dart';
StyledToast(
  textStyle: TextStyle(fontSize: 16.0, color: Colors.white),
  backgroundColor: Color(0x99000000),
  borderRadius: BorderRadius.circular(5.0),
  textPadding: EdgeInsets.symmetric(horizontal: 17.0, vertical: 10.0),
  toastPositions: StyledToastPosition.bottom,
  toastAnimation: StyledToastAnimation.fade,
  reverseAnimation: StyledToastAnimation.fade,
  curve: Curves.fastOutSlowIn,
  reverseCurve: Curves.fastLinearToSlowEaseIn,
  duration: Duration(seconds: 4),
  animDuration: Duration(seconds: 1),
  dismissOtherOnShow: true,
  movingOnWindowChange: true,
  child: MaterialApp(
          title: appTitle,
          showPerformanceOverlay: showPerformance,
          home: LayoutBuilder(
            builder: (BuildContext context, BoxConstraints constraints) {
              return MyHomePage(
                title: appTitle,
                onSetting: onSettingCallback,
              );
            },
          ),
        ),
);
//general use
showToast("hello styled toast");

// Customize toast content widget
showToastWidget(Text('hello styled toast'));

? 路线图


默认吐司小部件

淡入动画

从顶部滑入动画

从底部滑入动画

从左侧滑入动画

从右侧滑入动画

缩放动画

淡入缩放动画

旋转动画

淡入旋转动画

缩放旋转动画

移除时

自定义吐司小部件

自定义失败吐司小部件

自定义成功吐司小部件

StyledToast 参数

属性 描述
child 小部件(非空)(必需)
textAlign 文本对齐(默认 TextAlign.center)
textDirection 文本方向(默认 TextDirection.ltr)
borderRadius 边框半径(BorderRadius.circular(5.0))
backgroundColor 颜色(默认 Color(0x99000000))
textPadding EdgeInsetsGeometry(默认 EdgeInsets.symmetric(horizontal: 17.0,vertical: 8.0))
toastHorizontalMargin 双精度(默认 50.0)
文本样式 文本样式(默认 TextStyle(fontSize: 16.0,fontWeight: FontWeight.normal,color: Colors.white))
shapeBorder ShapeBorder(默认 RoundedRectangleBorder(borderRadius: borderRadius))
duration 持续时间(默认 2.3秒)
animDuration 持续时间(默认 400毫秒,animDuration * 2 <= duration,必须满足条件才能正常显示吐司)
toastPositions StyledToastPosition(默认 StyledToastPosition.bottom)
toastAnimation StyledToastAnimation(默认 StyledToastAnimation.fade)
reverseAnimation StyledToastAnimation
alignment AlignmentGeometry(默认 Alignment.center)
axis Axis(默认 Axis.vertical)
startOffset 偏移量
endOffset 偏移量
reverseStartOffset 偏移量
reverseEndOffset 偏移量
curve Curve(默认 Curves.linear)
reverseCurve Curve(默认 Curves.linear)
dismissOtherOnShow 布尔值(默认 true)
movingOnWindowChange 布尔值(默认 true)
onDismiss VoidCallback(吐司移除时调用)

showToast 参数

属性 描述
msg 字符串(非空)(必需)
context BuildContext(如果您没有使用StyledToast包装应用,则需要context,否则不需要)
duration 持续时间(默认 2.3秒)
animDuration 持续时间(默认 400毫秒,animDuration * 2 <= duration,必须满足条件才能正常显示吐司)
position StyledToastPosition(默认 StyledToastPosition.bottom)
文本样式 文本样式(默认 TextStyle(fontSize: 16.0,fontWeight: FontWeight.normal,color: Colors.white))
textPadding EdgeInsetsGeometry(默认 EdgeInsets.symmetric(horizontal: 17.0,vertical: 8.0))
backgroundColor 颜色(默认 Color(0x99000000))
borderRadius 边框半径(BorderRadius.circular(5.0))
shapeBorder ShapeBorder(默认 RoundedRectangleBorder(borderRadius: borderRadius))
onDismiss VoidCallback(吐司移除时调用)
textDirection 文本方向(默认 TextDirection.ltr)
dismissOtherOnShow 布尔值(默认 true)
movingOnWindowChange 布尔值(默认 true)
toastAnimation StyledToastAnimation(默认 StyledToastAnimation.fade)
reverseAnimation StyledToastAnimation
alignment AlignmentGeometry(默认 Alignment.center)
axis Axis(默认 Axis.vertical)
startOffset 偏移量
endOffset 偏移量
reverseStartOffset 偏移量
reverseEndOffset 偏移量
textAlign 文本对齐(默认 TextAlign.center)
curve Curve(默认 Curves.linear)
reverseCurve Curve(默认 Curves.linear)

showToastWidget 参数

属性 描述
widget 小部件(非空)(必需)
context BuildContext(如果您没有使用StyledToast包装应用,则需要context,否则不需要)
duration 持续时间(默认 2.3秒)
animDuration 持续时间(默认 400毫秒,animDuration * 2 <= duration,必须满足条件才能正常显示吐司)
onDismiss VoidCallback(吐司移除时调用)
dismissOtherOnShow 布尔值(默认 true)
movingOnWindowChange 布尔值(默认 true)
textDirection 文本方向(默认 TextDirection.ltr)
position StyledToastPosition(默认)
animation StyledToastAnimation(默认 StyledToastAnimation.fade)
reverseAnimation StyledToastAnimation
alignment AlignmentGeometry(默认 Alignment.center)
axis Axis(默认 Axis.vertical)
startOffset 偏移量
endOffset 偏移量
reverseStartOffset 偏移量
reverseEndOffset 偏移量
curve Curve(默认 Curves.linear)
reverseCurve Curve(默认 Curves.linear)

示例

示例

GitHub

https://github.com/JackJonson/flutter_styled_toast