当前位置:网站首页>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
边栏推荐
- Ap和F107数据来源及处理
- Atcoder beginer contest 169 (B, C, D unique decomposition, e mathematical analysis f (DP))
- What is generics- Introduction to generics
- ETH数据集下载及相关问题
- linux安装postgresql + patroni 集群问题
- 相信自己,这次一把搞定JVM面试
- Lampe respiratoire PWM
- 超卓航科上市:募资9亿市值超60亿 成襄阳首家科创板企业
- Youzan won the "top 50 Chinese enterprise cloud technology service providers" together with Tencent cloud and Alibaba cloud [easy to understand]
- 【征文活动】亲爱的开发者,RT-Thread社区喊你投稿啦
猜你喜欢

移动应用性能工具探索之路

一文看懂:数据指标体系的4大类型

PhD battle-11 preview | review and prospect backdoor attack and defense of neural network

Just a coincidence? The mysterious technology of apple ios16 is even consistent with the products of Chinese enterprises five years ago!

Sword finger offer 21 Adjust the array order so that odd numbers precede even numbers

Digital IC hand tearing code -- voting device

【Leetcode】13. Roman numeral to integer

亚马逊云科技 Community Builder 申请窗口开启
![L'explosion de John utilise l'encodage d'entrée par défaut: UTF - 8 Loaded 1 password Hash (bcrypt [blowfish 32 / 64 X3])](/img/4c/ddf7f8085257d0eb8766dbec251345.png)
L'explosion de John utilise l'encodage d'entrée par défaut: UTF - 8 Loaded 1 password Hash (bcrypt [blowfish 32 / 64 X3])

剑指 Offer 26. 树的子结构
随机推荐
相信自己,这次一把搞定JVM面试
MOSFET器件手册关键参数解读
Interpretation of key parameters in MOSFET device manual
System Verilog implements priority arbiter
Seven charts, learn to do valuable business analysis
871. 最低加油次数
AP and F107 data sources and processing
Leetcode1380: lucky numbers in matrix
Domestic relatively good OJ platform [easy to understand]
易语言abcd排序
[cloud native] briefly talk about the understanding of flume, a massive data collection component
What if the default browser cannot be set?
Blog theme "text" summer fresh Special Edition
二、mock平台的扩展
Connect Porsche and 3PL EDI cases
Dgraph: large scale dynamic graph dataset
Changwan group rushed to Hong Kong stocks: the annual revenue was 289million, and Liu Hui had 53.46% voting rights
Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
VMware install win10 image
Configure ARP table entry restrictions and port security based on the interface (restrict users' private access to fool switches or illegal host access)