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

swipe_to 封面
插件详情v1.0.6

swipe_to

SwipeTo 是一个聊天视图小部件的包装器,当用户在上面水平滑动时可以触发回调。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
8160
喜欢数
351
Pub 分数
160

安装插件

flutter pub add swipe_to

插件介绍

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

SwipeTo 是一个 Flutter 包,它封装了聊天视图小部件,使开发者能够在用户执行水平滑动手势时触发回调。该包专为聊天界面设计,其中滑动手势可以启动诸如删除消息或快速回复等操作。该包支持多种平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,使其适用于跨平台应用。通过简单的 API,它可以无缝集成到现有的聊天 UI 中,无需复杂的设置。它通过为聊天元素添加基于手势的功能来增强用户交互。

适合场景

  • 聊天消息删除
  • 快速回复操作
  • 手势驱动的导航
  • 交互式聊天界面
  • 滑动关闭消息
  • 增强的用户参与度

主要特点

  • 水平滑动检测
  • 回调在滑动时触发
  • 跨平台兼容性
  • 与聊天组件的简单集成
  • 支持多个平台
  • 轻量且开销极小

适合对象

  • 开发聊天应用的开发者
  • 寻求手势交互的UI设计师
  • 需要滑动操作功能的应用
  • 跨平台移动和网页应用
  • 交互式消息接口

使用建议

  • 需要正确的手势处理设置
  • 可能需要针对复杂的滑动行为进行定制
  • 仅限水平滑动
  • 取决于底层聊天窗口结构
  • 不适用于垂直滑动场景

原始 README

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

swipe_to

SwipeTo is a wrapper for a chat view widget which can be used initiate callback when user horizontally swipe on it.

Getting Started

To use this packages, you just simply need to wrap your child component in SwipeTo widget and pass a VoidCallback that you can carry forward with your task.

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

dependencies:
  ...
  swipe_to: 1.0.6

In your library add the following import:

import 'package:swipe_to/swipe_to.dart';

Parameter Info

  • child : (@required) StateLess or StateFull flutter widget.
  • onRightSwipe : callback which will be initiated at the end of right swipe animation. If not passed right swipe will be disabled
  • onLeftSwipe : callback which will be initiated at the end of left swipe animation. If not passed left swipe will be disabled
  • iconOnRightSwipe : IconData that will be displayed on left beneath child widget when swiped right. If not specified default is Icons.reply
  • rightSwipeWidget : Widget that will be displayed beneath child widget when swipe right. If iconOnRightSwipe is defined this will have no effect.
  • iconOnLeftSwipe : IconData that will be displayed on right beneath child widget when swiped left. If not specified default is Icons.reply
  • leftSwipeWidget : Widget that will be displayed beneath child widget when swipe left. If iconOnLeftSwipe is defined this will have no effect.
  • iconSize : Double value defining size of displayed icon beneath child widget. If not specified default it will take 26
  • iconColor : Color value defining color of displayed icon beneath child widget. If not specified primaryColor from theme will be taken
  • offsetDx : Double dx value used in Offset() till which position of child widget will get animated. If not specified 0.3 default will be taken. onRightSwipe +dx value will be used and for onLeftSwipe -dx value will be used
  • animationDuration : Duration value to define animation duration. If not specified default is 150 milliseconds
  • swipeSensitivity : Swipe sensitivity integer value which will be in range of default min 5 to max 35. Crossing mentioned value of this parameter (+ve in right and -ve in left direction) will trigger swipe animation.

Major changes onwards [ver 0.0.1+5]

  • For a single child widget, we can now enable swipe for both left and right direction
  • swipeDirection parameter is removed. Now onLeftSwipe and onRightSwipe callback will enable swiping for a particular direction if passed
  • iconData is now split into two parameter, iconOnRightSwipe & iconOnLeftSwipe for future use
  • endOffset is now change to accept a double value only
  • callBack is now split into two parameter, onLeftSwipe & onRightSwipe

Using SwipeTo widget for ListView items

While using SwipeTo widget for ListView items, make sure to pass a Key() as key parameter of SwipeTo widget. Suggested to use UniqueKey() which will differentiate each individual widget in the Widget Tree. Check example below. To view example code click here.

ListView(
    children: snapshot.data!.map((name) {
        return SwipeTo(
            key: UniqueKey(),
            iconOnLeftSwipe: Icons.arrow_forward,
            iconOnRightSwipe: Icons.arrow_back,
            onRightSwipe: (details) {
                log("\n Left Swipe Data --> $name");
            },
            swipeSensitivity: 20,
            child: ListTile(
                tileColor: Colors.cyan.shade200,
                title: Text(name),
            ),
        );
    }).toList(),
);

Deprecated/Removed Parameters

  • swipeDirection : Enum value from [swipeToLeft, swipeToRight] only. Make sure to pass relative Offset value according to passed swipeDirection value. If not specified swipeToRight will be taken as default.
  • iconData : IconData that will be displayed beneath child widget. if not specified default is Icons.reply
  • endOffset : Offset value till which position of child widget will get animated. if not specified Offset(0.3, 0.0) default will be taken
  • callBack : (@required) callback which will be initiated at the end of swipe animation

Example : SwipeToRight Wrap your desired widget with SwipeTo & pass a call to onRightSwipe parameter.

SwipeTo(
    child: Container(
        padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 8.0),
        child: Text('Hey You! Swipe me right 👉🏿'),
    ),
    onRightSwipe: (details) {
        print('Callback from Swipe To Right');
    },
),

Example : SwipeToLeft Wrap your desired widget with SwipeTo & pass a call to onLeftSwipe parameter.

SwipeTo(
    child: Container(
        padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 8.0),
        child: Text('👈🏿 Hey You! Swipe me Left'),
    ),
    onLeftSwipe: (details) {
        print('Callback from Swipe To Left');
    },
),

Example : SwipeToLeft & SwipeToRight Wrap your desired widget with SwipeTo & pass a call to onLeftSwipe & onRightSwipe parameters.

SwipeTo(
    child: Container(
        padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 8.0),
        child: Text('👈🏿 Swipe me Left | YOU |Swipe me right 👉🏿'),
    ),
    onLeftSwipe: (details) {
        print('Callback from Swipe To Left');
    },
    onRightSwipe: (details) {
        print('Callback from Swipe To Right');
    },
),

Sample Outputs

Swipe To iOS Output Swipe To Android Output Swipe To iOS Output with Widget in back Swipe To Android Output with Widget in back

References to learn

https://medium.com/@purvik1239/enable-swiping-right-left-for-your-flutter-application-widgets-a7b556674f9c

所属分类

源码仓库

使用此插件的项目