搜索插件、代码仓与 APP 分类

flutter_sliding_toast 封面
插件详情v1.8.0

flutter_sliding_toast

一个用于显示带有自定义样式和动画行为的消息的 Flutter 包。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1030
喜欢数
51
Pub 分数
160

安装插件

flutter pub add flutter_sliding_toast

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,可在多个平台上显示可自定义的吐司消息,并带有平滑的滑动动画。它支持定制化样式,包括颜色、字体和位置,并允许开发者定义自定义动画行为,以提供精致的用户体验。非常适合在不干扰应用流程的情况下提供简短反馈或通知。该包轻量且可无缝集成到现有的 Flutter 项目中。

适合场景

  • 在操作后显示用户反馈
  • 显示成功或错误消息
  • 在应用中提供临时警报
  • 通过动画通知增强用户界面
  • 自定义消息外观和行为

主要特点

  • 滑动动画效果
  • 可自定义的样式选项
  • 跨平台兼容性
  • 与 Flutter 的轻松集成
  • 支持多种消息类型
  • 可配置的动画持续时间和方向

适合对象

  • 移动和Web应用
  • 需要细微通知的应用程序
  • 寻求动画反馈的开发者
  • 面向用户界面的 Flutter 项目
  • 希望轻量级提示解决方案的团队

使用建议

  • 仅限基本的吐司功能
  • 无内置的复杂布局支持
  • 动画自定义需要代码知识
  • 可能需要额外的样式以支持深色模式
  • 不适用于持久通知

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Flutter Sliding Toast

pub license: MIT

Enhance your app's UI with customizable, interactive toasts! This package offers both sliding & popup styles, with features like animation control, tap actions, and multiple dismiss options.

🎨 Screenshots

🎯 Features

  • Show sliding toasts, modify sliding behaviors
  • Show popup toasts, disable or modify fading and scaling behaviors
  • Change toast's alignment positions and sliding toast's sliding directions
  • Define animation and display duration, max height and width, padding
  • Set title, leading, trailing widgets and make title width dynamic or expanded
  • Disable the progressbar in sliding toast if needed
  • Use glassmorphism/gradient/decorated background or default success and error toast
  • Slide any direction to dismiss sliding toast and vertically for popup toast
  • Dismiss an individual or all toasts programmatically
  • Pause the animation with long press and release it to continue
  • Execute a function after the toast is tapped or disposed
  • Disable Multiple tapping to execute 'onTap' callback only one time
  • Initialize context or overlay state early for persistent toast availability

⚙️ Getting Started

Requires Flutter 3.47.0 or newer.

Add the following line to pubspec.yaml:

dependencies:
  flutter_sliding_toast: ^1.6.0

🚀 Usage

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        iconTheme: const IconThemeData(color: Colors.white),
        title: const Text('Sliding & Popup Toast'),
        centerTitle: true,
      ),
      body: SafeArea(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const SizedBox(width: double.maxFinite),
            ElevatedButton(
              onPressed: () {
                InteractiveToast.slide(
                  context: context,
                  leading: _leadingWidget(),
                  title: const Text(
                    "Hi there! I'm a sliding toast 😎. "
                    'Dismiss me by sliding upward.',
                  ),
                  trailing: _trailingWidget(),
                  toastStyle: const ToastStyle(titleLeadingGap: 10),
                  toastSetting: const SlidingToastSetting(
                    displayDuration: Duration(seconds: 2),
                    toastStartPosition: ToastPosition.top,
                    toastAlignment: Alignment.topCenter,
                  ),
                );
              },
              child: _textWidget('Sliding toast from top center'),
            ),
            const SizedBox(height: 30),
            ElevatedButton(
              onPressed: () {
                final overlayState = Overlay.of(context);
                InteractiveToast.pop(
                  overlayState: overlayState,
                  title: const Text(
                    "Hi! I'm a popup toast 🐺. "
                    'I have fading and scaling effect.',
                  ),
                  trailing: _trailingWidget(),
                  toastSetting: const PopupToastSetting(
                    animationDuration: Duration(seconds: 1),
                    displayDuration: Duration(seconds: 3),
                  ),
                );
              },
              child: _textWidget('Popup toast at bottom center'),
            ),
          ],
        ),
      ),
    );
  }

  Text _textWidget(String text) =>
      Text(text, style: const TextStyle(fontSize: 16));

  Icon _trailingWidget() => const Icon(Icons.person, color: Colors.deepPurple);

  Container _leadingWidget() {
    return Container(
      width: 40,
      height: 40,
      decoration: BoxDecoration(
        shape: BoxShape.circle,
        color: Colors.purple,
        boxShadow: [
          BoxShadow(
            color: Colors.black.withAlpha(25),
            spreadRadius: 3,
            blurRadius: 4,
          ),
        ],
      ),
      alignment: Alignment.center,
      child: const Text('🦄', style: TextStyle(fontSize: 20)),
    );
  }
}

❤️ Additional information

Pull requests are welcomed!

If you encounter any problems or you have any ideas, feel free to open an issue:

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。