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

swipeable_tile 封面
插件详情v2.0.1

swipeable_tile

一个用于带动画背景的关闭功能的包。还支持滑动触发操作但不关闭。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
4340
喜欢数
214
Pub 分数
150

安装插件

flutter pub add swipeable_tile

插件介绍

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

SwipeableTile 是一个 Flutter 包,可实现带有自定义背景效果的动画删除功能。它支持滑动删除手势以及滑动触发操作但不删除项目。非常适合用于实现具有视觉反馈的交互式列表项,可在 Android、iOS、Web、macOS、Windows 和 Linux 等主要平台上运行。该包通过提供流畅的动画和灵活的手势处理,增强了基于列表界面的用户体验。

适合场景

  • 在列表中实现滑动删除功能
  • 使用操作触发器创建交互式列表项
  • 为任务管理应用构建直观的用户界面
  • 为列表项交互添加动画反馈
  • 设计响应式卡片布局
  • 通过滑动手势提升用户参与度

主要特点

  • 滑动时的动画背景
  • 支持取消和触发操作的滑动
  • 跨平台兼容性
  • 可自定义的滑动阈值
  • 平滑的动画过渡
  • 滑动行为的灵活配置

适合对象

  • 开发交互式列表界面的开发者
  • 需要基于滑动手势交互的应用程序
  • UI 设计师专注于基于手势的体验
  • 针对多个平台的项目
  • 希望使用轻量级手势解决方案的团队
  • 具有丰富触控反馈的移动优先应用

使用建议

  • 可能需要额外的样式来处理复杂的背景
  • 大型列表的性能影响
  • 动画曲线的内置自定义功能有限
  • 未针对极高频率的滑动事件进行优化
  • 在滑动操作期间需要仔细处理状态
  • 最适合中等大小的列表以保持响应性

原始 README

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

Loading Animation Widget

YouTube Badge Twitter Badge Patreon Badge BMC Badge pub package WateryDesert


Features

Animated tile and backgound while swiping. Add padding to tile. Swipe to trigger action.

The package is fork of Dismissible. Without any vertical, up and down swipe.

Problems with dismissible
  1. Dismissible doesn't allow animated rounded corner and elevation similar to google Gmail, Telegram, Messages (these are android apps) if you swipe you will notice. Here is the result with Dismissible.

  1. Dismissible can't make rounded Card there is always some UI issue. Here is the result with Dismissible.

  1. It's not possible to animated the background while swiping.

  2. Swipe to trigger action function. Similar to telegram or instagram DM message reply.

How to use?

Installation

Add swipeable_tile to your pubspec.yaml dependencies then run flutter pub get

dependencies:
  swipeable_tile:
Import

Add this line to import the package.

import 'package:swipeable_tile/swipeable_tile.dart';
Do and don't
  • Don't call setState() from backgroundBuilder.
  • Set the Scaffold's (or whatever background widget you are using) backgroundColor and SwipeableTile or SwipeableTile.swipeToTrigger's color same.
There are four named constructors:
  1. SwipeableTile When the tile is swiped there will be an elevation (remove elevation by setting isElevated to false) and rounded corner to the tile (set borderRadius to 0 if you don't want rounded corner).
SwipeableTile(
  color: Colors.white,
  swipeThreshold: 0.2,
  direction: SwipeDirection.horizontal,
  onSwiped: (direction) {// Here call setState to update state
  },
  backgroundBuilder: (context, direction, progress) {
    if (direction == SwipeDirection.endToStart) {
      // return your widget
    } else if (direction == SwipeDirection.startToEnd) {
      // return your widget
    }
    return Container();
  },
  key: UniqueKey(),
  child: // Here Tile which will be shown at the top
),

  1. SwipeableTile.card This will make the tile look like card with constant rounded corner, unlike SwipeableTile. You also have to set the padding which will wrap around the tile as well background.
SwipeableTile.card(
  color: Color(0xFFab9ee8),
  shadow: BoxShadow(
    color: Colors.black.withOpacity(0.35),
    blurRadius: 4,
    offset: Offset(2, 2),
  ),
  horizontalPadding: 16,
  verticalPadding: 8,
  direction: SwipeDirection.horizontal,
  onSwiped: (direction) {
    // Here call setState to update state
  },
  backgroundBuilder: (context, direction, progress) {
      // You can animate background using the progress
    return AnimatedBuilder(
      animation: progress,
      builder: (context, child) {
        return AnimatedContainer(
          duration: const Duration(milliseconds: 400),
          color: progress.value > 0.4
              ? Color(0xFFed7474)
              : Color(0xFFeded98),
        );
      },
    );
  },
  key: UniqueKey(),
  child: Padding(
    padding: const EdgeInsets.symmetric(vertical: 4.0),
    child: // Here Tile which will be shown at the top
  ),
),
  1. SwipeableTile.swipeToTrigger This is exactly the same as SwipeableTile but instead of dismiss it, it will trigger an action. The tile will return back to initial position when maximum drag reaches swipeThreshold

  2. SwipeableTile.swipeToTriggerCard This is exactly the same as SwipeableTile.card but instead of dismiss it, it will trigger an action. The tile will return back to initial position when maximum drag reaches swipeThreshold

You can build the background dynamically and animate them using backgroundBuilder. Use direction parameter to check swipe direction and show different widget.

backgroundBuilder: (context, direction, progress) {
   if (direction == SwipeDirection.endToStart) {
       return Container(color: Colors.red);
   } else if (direction == SwipeDirection.startToEnd) {
       return Container(color: Colors.blue);
   }
   return Container();
},

The progress is basically the same animation controller responsible for tile slide animation. You can use this controller to animate the background.

To trigger vibration you have to check when tile is dragged certain animation controller value. And I used vibration package for vibration and worked batter than HapticFeedback

backgroundBuilder: (context, direction, progress) {
    bool vibrated = false;
    return AnimatedBuilder(
        animation: progress,
        builder: (context, child) {
        if (progress.value > 0.2 && !vibrated) {
            Vibration.vibrate(duration: 40);
            vibrated = true;
        } else if (progress.value < 0.2) {
            vibrated = false;
        }
    // return your background
        },
    );
},

swipeThreshold defines how far you can drag and will consider as dismiss. In case of swipe to trigger this will define maximun drag limit.

How to swipe to trigger action?

It's possible to do from backgroundBuilder using progress parameter but to select exact message (or tile) requires calling setState() which is not possible from backgroundBuilder however you can call setState() from onSwiped callback which will invoke when the tile return to initial position.

Vibrate & animate the icon when it's dragged maximum by checking progress.isCompleted or you can check animation value. Then call setState() from onSwiped User will not notice unless you set movementDuration to longer time and swipeThreshold to 0.4 (which is default). Check the example app how it's implemented.


All flutter packages

● Sliding Clipped Nav Bar
● Water Drop Nav Bar
➜ Swipeable Tile
● Loading Animation Widget


所属分类

源码仓库

使用此插件的项目

暂无相关数据。