搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案

所在榜單