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

touchable_opacity 封面
插件详情v1.2.0

touchable_opacity

此小部件允许您在用户与您的应用交互时提供更直观的反馈,类似于 React Native 中的 TouchableOpacity。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
7000
喜欢数
17
Pub 分数
140

安装插件

flutter pub add touchable_opacity

插件介绍

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

touchable_opacity 包提供了一个 Flutter 小部件,当用户与 UI 元素交互时会提供视觉反馈,模仿 React Native 中 TouchableOpacity 的行为。通过在按下时微妙地改变不透明度,它增强了用户体验,使交互感觉更加响应迅速。该包兼容所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,可无缝集成到现有的 Flutter 项目中。该包轻量且设计简洁,专注于直观的触摸反馈,而无需增加额外的复杂性。

适合场景

  • 为按钮添加交互反馈
  • 提升移动和网页应用的用户体验
  • 创建响应式 UI 元素
  • 通过视觉提示增强可访问性
  • 简化表单中的手势处理

主要特点

  • 基于不透明度的按压反馈
  • 跨平台兼容性
  • 所需设置最少
  • 匹配 React Native 的 TouchableOpacity 行为
  • 轻量且高效

适合对象

  • 熟悉 React Native 的 Flutter 开发人员
  • 需要一致触控反馈的应用程序
  • 以UI为主的应用程序
  • 寻求简单手势增强功能的开发者
  • 面向多个平台的项目

使用建议

  • 仅限透明度变化(无其他动画)
  • 不适合复杂的手势交互
  • 可能需要额外的样式设置以实现自定义效果
  • 依赖外部源代码仓库
  • 无内置的触觉反馈支持

原始 README

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

touchable_opacity

Version Build Status codecov

This package gives you access to the Touchableopacity widget. This widget uses the GestureDetector to allow interaction and animated to opacity of the widget on touch events.

Installing

Add the package to your pubspec.yaml file

dependencies:
	touchable_opacity: 1.2.0
Usage

Import the package using

import 'package:touchable_opacity/touchable_opacity.dart';

And simply use it as any other widget.

Container(
	child: TouchableOpacity(
		activeOpacity: 0.4,
		child: FlutterLogo(),
	),
),
Configuration

TouchableOpacity uses gestureDetector internally and tries to maintain all the different behaviours and interactions that gesture detector enables. To understand the different touch events that you can configure please visit the GestureDetector API docs here.

activeOpacity: double value that TouchableOpacity uses to animate the opacity of the child when a touch down event is received. The value must be between 1.0 and 0.0, the default value is 0.2 .

Example

The code found in the example folder of this repo shows how to use this package to render the content shown in the sample GIF. The folder contains a Flutter application that you can run yourself. Go here to jump into the code.

Support

If you have any issues with using this package, or have any ideas you thnk are good additions please create an issue here

Known Issues

Because of the way GestureDetector renders, TouchableOpacity fills its parent. If you want to bound the size to that of its child simply place the TouchableOpacity widget in any one of the Layout widgets, you can see a list of layout widgets available in flutter here

所属分类

源码仓库

使用此插件的项目