Toasty Box

Toasty Box 是一个用于在您的应用中显示精美动画吐司的 Flutter 插件。它具有完全可定制的功能和令人惊叹的动画。

Toasty box Example Video

安装

要使用此插件,请将其添加到您的 pubspec.yaml 文件中

dependencies:
  toasty_box: ^1.0.1

然后,运行

$ flutter pub get

用法

基本用法

导入包

import 'package:toasty_box/toasty_box.dart';

显示一条简单的消息吐司

ToastService.showToast(
                  context,
                  message: "This is a message toast ??!",
                );

非常简单,不是吗??

消息吐司 Widget 吐司
Message Toast Image Widget Toast Image

自定义

您可以通过提供额外的参数来定制吐司的外观。

对于消息吐司 –

ToastService.showToast(
                  context,
                  isClosable: true,
                  backgroundColor: Colors.teal.shade500,
                  shadowColor: Colors.teal.shade200,
                  length: ToastLength.medium,
                  expandedHeight: 100,
                  message: "This is a message toast ??!",
                  messageStyle: TextStyle(fontSize: 18),
                  leading: const Icon(Icons.messenger),
                  slideCurve: Curves.elasticInOut,
                  positionCurve: Curves.bounceOut,
                  dismissDirection: DismissDirection.none,
                );

对于 Widget 吐司 –

ToastService.showWidgetToast(
                  context,
                  isClosable: true,
                  backgroundColor: Colors.teal.shade500,
                  shadowColor: Colors.teal.shade200,
                  length: ToastLength.medium,
                  expandedHeight: 100,
                  leading: const Icon(Icons.messenger),
                  slideCurve: Curves.elasticInOut,
                  positionCurve: Curves.bounceOut,
                  dismissDirection: DismissDirection.none,
                  child: Container(
                  	color: Colors.blue,
                  	child: Center(
                  		child: Text('This is widget toast!'),
                  	),
                  ),
                );

自定义选项

  • message: 要在吐司中显示的消息文本。
  • messageStyle: 要在吐司中显示的消息文本样式
  • leading: 吐司中的前导小部件
  • isClosable: 显示关闭按钮作为尾随小部件
  • expandedHeight: 点击吐司时,吐司从屏幕底部算起的高度
  • length: 吐司的持续时间,以 ToastLength 枚举表示 – [short,medium,long,ages,never]
  • backgroundColor: 吐司的背景颜色。
  • shadowColor: 吐司的阴影颜色
  • slideCurve: 重新排序吐司列表时的动画曲线
  • positionCurve: 吐司进入和退出屏幕时的动画曲线
  • child: 吐司中要显示的小部件

此外,我还为您准备了另外 3 种类型的吐司模板 –

用于成功吐司

ToastService.showSuccessToast(
                  context,
                  length: ToastLength.medium,
                  expandedHeight: 100,
                  message: "This is a success toast ?!",
                );

Widget Toast Image

用于警告吐司

ToastService.showWarningToast(
                  context,
                  length: ToastLength.medium,
                  expandedHeight: 100,
                  message: "This is a warning toast!",
                );

Widget Toast Image

用于错误吐司

ToastService.showErrorToast(
  context,
  length: ToastLength.medium,
  expandedHeight: 100,
  message: "This is an error toast!",
);

Widget Toast Image

示例

请查看示例文件夹,了解如何全面使用此插件。示例演示了各种自定义选项和用例。您可以使用以下命令运行示例:

$ cd example
$ flutter run

贡献

我们欢迎贡献!如果您发现任何问题或有改进建议,请随时打开 issue 或提交 pull request。

许可证

本项目根据 MIT 许可证授权 – 更多详情请参阅 LICENSE.md 文件。


MIT License

Copyright (c) 2023 YE LWIN OO

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

?? 更多更新即将推出…

GitHub

查看 Github