Future _unfollowSchool() async {
var params = {
'phoneNum':phoneNum,
'schoolName':widget.arguments['title']
};
print('params:${params}');
await request('unfollowSchool','delete',params).then((val){
if(val['msg']=='成功'){
setState(() {
_hasStar = false;
});
_toast('取消收藏成功',1);
}else{
_toast(val['msg'],0);
}
});
return _hasStar;
}
// debounce.dart
import 'dart:async';
/// 函数防抖
///
/// [func]: 要执行的方法
/// [delay]: 要迟延的时长
Function debounce(
Function func, [
Duration delay = const Duration(milliseconds: 500),
]) {
Timer timer;
Function target = () {
if (timer?.isActive ?? false) {
timer?.cancel();
}
timer = Timer(delay, () {
func?.call();
});
};
return target;
}
这里发现,先toast弹框要后弹出,先改变按钮颜色,会让视觉效果好很多,toast先运行的话会等几秒,感觉上像按钮故障或者反应迟钝
防抖的效果不如节流流畅,记得时间要设置的小一点