需求
下拉到可刷新位置时震动
flutter version: 3.22.2
仅在该版本测试,其他版本未测试。
方法
各有优缺点,本文使用方案3,建议使用方案2。
1.修改SDK中的RefreshIndicator(pass)
2.Copy RefreshIndicator,在原控件上加逻辑(更稳定,推荐)
3.监听ScrollNotification(更灵活,本文使用)
How Use
ListenReadyRefresh(
//到达位置时回调
ready: () async => Vibration.vibrate(
amplitude: await Vibration.hasAmplitudeControl() == true ? 1 : -1,
duration: 50),
child: RefreshIndicator(
triggerMode: RefreshIndicatorTriggerMode.anywhere,
child:....))
ListenReadyRefresh Widget 实现
通过ScrollNotification计算下,复制RefreshIndicator计算逻辑,到达位置时触发回调;
import 'dart:ui';
import