当前位置:网站首页>Shutter: action feedback
Shutter: action feedback
2022-07-02 17:14:00 【J_ D_ Chi】
Write it at the front
stay Android or iOS On the device , The system will provide feedback of sound or vibration to help us make users operate , It plays a role of informing the user that this operation is effective . This article is mainly summarized in Flutter On , How to use these functions .
Content
Feedback
Generally we use GestureDetector Will use it onTap or onLongTap Method , Now we can use FeedBack Class to help us add platform specific feedback .
class WidgetWithWrappedHandler extends StatelessWidget {
const WidgetWithWrappedHandler({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: Feedback.wrapForTap(_onTapHandler, context),
onLongPress: Feedback.wrapForLongPress(_onLongPressHandler, context),
child: const Text('X'),
);
}
void _onTapHandler() {
// Respond to tap.
}
void _onLongPressHandler() {
// Respond to long press.
}
}
According to the current official documents Feedback Introduction of methods , stay Android On , Click to play the click system sound , Long press, there will be vibration feedback . And in the iOS There will be no feedback , because iOS There is usually no response to these two operations .
Feedback Two other methods are also provided forTap and forLongPress, To further help us do more work on feedback , For example, judge whether there are other conditions for this operation , To implement feedback .
class WidgetWithExplicitCall extends StatelessWidget {
const WidgetWithExplicitCall({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
// Do some work (e.g. check if the tap is valid)
Feedback.forTap(context);
// Do more work (e.g. respond to the tap)
},
onLongPress: () {
// Do some work (e.g. check if the long press is valid)
Feedback.forLongPress(context);
// Do more work (e.g. respond to the long press)
},
child: const Text('X'),
);
}
}
HapticFeedback
stay Flutter Of services In the bag , There is one HapticFeedback class , There are several static methods , Used to provide vibration feedback :
class HapticFeedback {
static Future<void> vibrate();
static Future<void> lightImpact();
static Future<void> mediumImpact();
static Future<void> heavyImpact();
static Future<void> selectionClick();
}
These methods are also Flutter Used in some official components of , For example, pull-down refresh , Adjust the time in the time selector .
Reference resources
Feedback class
HapticFeedback class
【Flutter Little knowledge 】 Vibration feedback HapticFeedback
边栏推荐
- GeoServer:发布PostGIS数据源
- OpenHarmony如何启动远程设备的FA
- VMware install win10 image
- 深度之眼(二)——矩阵及其基本运算
- [leetcode] 14. Préfixe public le plus long
- Geoserver: publishing PostGIS data sources
- Cell:清华程功组揭示皮肤菌群的一种气味挥发物促进黄病毒感染宿主吸引蚊虫...
- Changwan group rushed to Hong Kong stocks: the annual revenue was 289million, and Liu Hui had 53.46% voting rights
- The macrogenome microbiome knowledge you want is all here (2022.7)
- 【Leetcode】13. 罗马数字转整数
猜你喜欢

Sword finger offer 25 Merge two sorted linked lists

Geoserver: publishing PostGIS data sources

Soul, a social meta universe platform, rushed to Hong Kong stocks: Tencent is a shareholder with an annual revenue of 1.28 billion

亚马逊云科技 Community Builder 申请窗口开启

使用知行之桥的API端口,提供资源供合作伙伴访问

Sword finger offer 22 The penultimate node in the linked list

畅玩集团冲刺港股:年营收2.89亿 刘辉有53.46%投票权

Tech Talk 活动预告 | 基于Amazon KVS打造智能视觉产品

超卓航科上市:募资9亿市值超60亿 成襄阳首家科创板企业

Dgraph: large scale dynamic graph dataset
随机推荐
ThreadLocal
Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers
Blog theme "text" summer fresh Special Edition
C语言中sprintf()函数的用法
Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
The impact of telecommuting on all aspects of our experience | community essay solicitation
Usage of sprintf() function in C language
lsf基础命令
2、 Expansion of mock platform
What will you do after digital IC Verification?
Amazon cloud technology community builder application window opens
剑指 Offer 24. 反转链表
jsp 和 servlet 有什么区别?
移动应用性能工具探索之路
入行数字IC验证后会做些什么?
对接保时捷及3PL EDI案例
什么是泛型?- 泛型入门篇
PhD Debate-11 预告 | 回顾与展望神经网络的后门攻击与防御
Serial port controls steering gear rotation
871. Minimum refueling times