当前位置:网站首页>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
边栏推荐
- 剑指 Offer 21. 调整数组顺序使奇数位于偶数前面
- Digital IC hand tearing code -- voting device
- Cell:清华程功组揭示皮肤菌群的一种气味挥发物促进黄病毒感染宿主吸引蚊虫...
- 871. 最低加油次数
- Just a coincidence? The mysterious technology of apple ios16 is even consistent with the products of Chinese enterprises five years ago!
- Qstype implementation of self drawing interface project practice (II)
- The macrogenome microbiome knowledge you want is all here (2022.7)
- 移动应用性能工具探索之路
- Geoserver: publishing PostGIS data sources
- How openharmony starts FA of remote devices
猜你喜欢
随机推荐
Notice on holding a salon for young editors of scientific and Technological Journals -- the abilities and promotion strategies that young editors should have in the new era
绿竹生物冲刺港股:年期内亏损超5亿 泰格医药与北京亦庄是股东
What is generics- Introduction to generics
深度之眼(三)——矩阵的行列式
Usage of sprintf() function in C language
体验居家办公完成项目有感 | 社区征文
[error record] error -32000 received from application: there are no running service protocol
OpenPose的使用
System Verilog实现优先级仲裁器
Seven charts, learn to do valuable business analysis
Sword finger offer 22 The penultimate node in the linked list
[cloud native] briefly talk about the understanding of flume, a massive data collection component
Sword finger offer 25 Merge two sorted linked lists
Use the API port of the bridge of knowledge and action to provide resources for partners to access
基于Impala的高性能数仓实践之执行引擎模块
L'explosion de John utilise l'encodage d'entrée par défaut: UTF - 8 Loaded 1 password Hash (bcrypt [blowfish 32 / 64 X3])
871. 最低加油次数
13、Darknet YOLO3
七张图,学会做有价值的经营分析
Tech Talk 活动预告 | 基于Amazon KVS打造智能视觉产品