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

flutter_slidable 封面
插件详情v5.2.0

flutter_slidable

一个带有可滑动操作的可滑动列表项的 Flutter 实现,支持方向性滑动操作并可被关闭。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
80.7万
喜欢数
6150
Pub 分数
150

安装插件

flutter pub add flutter_slidable

插件介绍

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

flutter_slidable 是一个 Flutter 包,可实现可滑动操作的交互式列表项,允许用户通过向左或向右滑动来显示操作按钮。它支持双向滑动和关闭手势,非常适合在列表中实现删除、归档或标记为已读等功能。该包可与 ListView 及其他可滚动小部件无缝集成,提供可自定义的动画和布局。它可在所有主要平台(包括 Android、iOS、Web、macOS、Windows 和 Linux)上运行。

适合场景

  • 在任务列表中实现滑动删除功能
  • 向联系人或消息添加上下文操作
  • 创建交互式待办事项界面
  • 在动态或收件箱中启用快速操作
  • 支持可关闭的通知
  • 构建响应式列表项交互

主要特点

  • 向左/向右滑动以显示操作
  • 内置的取消手势支持
  • 可自定义的操作按钮
  • 滑动时的平滑动画
  • 跨平台兼容性
  • 灵活的布局配置

适合对象

  • 开发交互式列表的开发者
  • 需要基于滑动的用户操作的应用程序
  • 具有动态列表项行为的项目
  • 注重跨平台一致用户体验的团队
  • 寻求轻量级且维护良好的包的用户

使用建议

  • 可能需要仔细处理嵌套滚动视图中的触摸事件
  • 应在不同屏幕尺寸上测试操作按钮的位置
  • 大型列表在未优化情况下的性能影响
  • 内置主题选项有限,仅限基本样式
  • 不适用于复杂的拖放交互

原始 README

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

Pub BuyMeACoffee

Slidable is a Flutter Favorite package!

flutter_slidable

A Flutter implementation of slidable list item with directional slide actions that can be dismissed.

Sponsors

Our top sponsors are shown below! [Become a Sponsor]


Try the Flutter Chat Tutorial  💬

Your complete platform for sending notifications

Migration from 0.6.0

You can read this small guide to migrate from the 0.6 to the 1.0 version: https://github.com/letsar/flutter_slidable/wiki/Migration-from-version-0.6.0-to-version-1.0.0

Features

  • Accepts start (left/top) and end (right/bottom) action panes.
  • Can be dismissed.
  • 4 built-in action panes.
  • 2 built-in slide action widgets.
  • 1 built-in dismiss animation.
  • You can easily create custom layouts and animations.
  • You can use a builder to create your slide actions if you want special effects during animation.
  • Closes when a slide action has been tapped (overridable).
  • Closes when the nearest Scrollable starts to scroll (overridable).
  • Option to disable the slide effect easily.

Install

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  flutter_slidable: <latest_version>

In your library add the following import:

import 'package:flutter_slidable/flutter_slidable.dart';

Getting started

Example:

Slidable(
  // Specify a key if the Slidable is dismissible.
  key: const ValueKey(0),

  // The start action pane is the one at the left or the top side.
  startActionPane: ActionPane(
    // A motion is a widget used to control how the pane animates.
    motion: const ScrollMotion(),

    // A pane can dismiss the Slidable.
    dismissible: DismissiblePane(onDismissed: () {}),

    // All actions are defined in the children parameter.
    children: const [
      // A SlidableAction can have an icon and/or a label.
      SlidableAction(
        onPressed: doNothing,
        backgroundColor: Color(0xFFFE4A49),
        foregroundColor: Colors.white,
        icon: Icons.delete,
        label: 'Delete',
      ),
      SlidableAction(
        onPressed: doNothing,
        backgroundColor: Color(0xFF21B7CA),
        foregroundColor: Colors.white,
        icon: Icons.share,
        label: 'Share',
      ),
    ],
  ),

  // The end action pane is the one at the right or the bottom side.
  endActionPane: const ActionPane(
    motion: ScrollMotion(),
    children: [
      SlidableAction(
        // An action can be bigger than the others.
        flex: 2,
        onPressed: doNothing,
        backgroundColor: Color(0xFF7BC043),
        foregroundColor: Colors.white,
        icon: Icons.archive,
        label: 'Archive',
      ),
      SlidableAction(
        onPressed: doNothing,
        backgroundColor: Color(0xFF0392CF),
        foregroundColor: Colors.white,
        icon: Icons.save,
        label: 'Save',
      ),
    ],
  ),

  // The child of the Slidable is what the user sees when the
  // component is not dragged.
  child: const ListTile(title: Text('Slide me')),
),

Motions

Any ActionPane has a motion parameter which allow you to define how the pane animates when the user drag the Slidable.

Behind Motion

The actions appear as if they where behind the Slidable:

Behind Motion

Drawer Motion

Animate the actions as if they were drawers, when the Slidable is moving:

Drawer Motion

Scroll Motion

The actions follow the Slidable while it's moving:

Scroll Motion

Stretch Motion

Animate the actions as if they were streched while the Slidable is moving:

Stretch Motion

Controller

You can use SlidableController to open or close the actions programmatically:

final controller = SlidableController();

// ...

Slidable(
  controller: controller,
  // ...
);

// ...

// Open the actions
void _handleOpen() {
  controller.openEndActionPane();
  // OR
  //controller.openStartActionPane();
}

void _handleOpen() {
  controller.close();
}

FAQ

You can read the FAQ here: https://github.com/letsar/flutter_slidable/wiki/FAQ

Sponsoring

I'm working on my packages on my free-time, but I don't have as much time as I would. If this package or any other package I created is helping you, please consider to sponsor me so that I can take time to read the issues, fix bugs, merge pull requests and add features to these packages.

Contributions

Feel free to contribute to this project.

If you find a bug or want a feature, but don't know how to fix/implement it, please fill an issue.
If you fixed a bug or implemented a feature, please send a pull request.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

所在榜单