当前位置:网站首页>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
边栏推荐
- js删除字符串中的子串
- Linux Installation PostgreSQL + Patroni cluster problem
- Cell: Tsinghua Chenggong group revealed an odor of skin flora. Volatiles promote flavivirus to infect the host and attract mosquitoes
- 小鹏P7雨天出事故安全气囊没有弹出 官方回应:撞击力度未达到弹出要求
- DGraph: 大规模动态图数据集
- Weili holdings listed on the Hong Kong Stock Exchange: with a market value of HK $500million, it contributed an IPO to Hubei
- Sword finger offer 22 The penultimate node in the linked list
- Atcoder beginer contest 169 (B, C, D unique decomposition, e mathematical analysis f (DP))
- In MySQL and Oracle, the boundary and range of between and precautions when querying the date
- PhD battle-11 preview | review and prospect backdoor attack and defense of neural network
猜你喜欢
一文看懂:数据指标体系的4大类型
Configure MySQL under Linux to authorize a user to access remotely, which is not restricted by IP
Connect Porsche and 3PL EDI cases
In MySQL and Oracle, the boundary and range of between and precautions when querying the date
【Leetcode】14. Longest Common Prefix
智能垃圾桶(五)——点亮OLED
Go zero micro service practical series (VIII. How to handle tens of thousands of order requests per second)
Sword finger offer 25 Merge two sorted linked lists
你想要的宏基因组-微生物组知识全在这(2022.7)
酒仙网IPO被终止:曾拟募资10亿 红杉与东方富海是股东
随机推荐
学习周刊-总第60期-2022年第25周
PWM controlled steering gear
2322. 从树中删除边的最小分数(异或和&模拟)
人生的开始
上传代码到远程仓库报错error: remote origin already exists.
QWebEngineView崩溃及替代方案
[essay solicitation activity] Dear developer, RT thread community calls you to contribute
Youzan won the "top 50 Chinese enterprise cloud technology service providers" together with Tencent cloud and Alibaba cloud [easy to understand]
Atcoder beginer contest 169 (B, C, D unique decomposition, e mathematical analysis f (DP))
js删除字符串中的子串
Executive engine module of high performance data warehouse practice based on Impala
Green bamboo biological sprint Hong Kong stocks: loss of more than 500million during the year, tiger medicine and Beijing Yizhuang are shareholders
System Verilog implements priority arbiter
IP地址转换地址段
[error record] error -32000 received from application: there are no running service protocol
Sword finger offer 24 Reverse linked list
【Leetcode】14. Longest Common Prefix
深度之眼(二)——矩阵及其基本运算
Error when uploading code to remote warehouse: remote origin already exists
What will you do after digital IC Verification?