- 清理大量废弃的 barrel 导出文件,移除冗余的中间导出层 - 修复所有相对路径导入错误,统一调整为扁平化模块引用 - 更新多平台 pubspec 版本号与依赖库版本 - 补充后端功能问题管理后台与脚本工具 - 调整部分页面的快捷方式文案适配新功能 - 更新部分翻译覆盖率与API文档
51 lines
1.2 KiB
Dart
51 lines
1.2 KiB
Dart
/// ============================================================
|
|
/// 闲言APP — 防抖工具
|
|
/// 创建时间: 2026-06-12
|
|
/// 更新时间: 2026-06-12
|
|
/// 作用: 回调式防抖器,用于搜索输入等场景
|
|
/// 上次更新: 初始创建
|
|
/// ============================================================
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
/// 回调式防抖器
|
|
/// 延迟执行回调,若在延迟期间再次调用则重置计时器
|
|
class Debouncer {
|
|
Debouncer({this.duration = const Duration(milliseconds: 300)});
|
|
|
|
/// 防抖延迟时长
|
|
final Duration duration;
|
|
|
|
Timer? _timer;
|
|
|
|
/// 调用防抖回调
|
|
/// 若上一次调用尚未执行,则取消并重新计时
|
|
void call(VoidCallback callback) {
|
|
_timer?.cancel();
|
|
_timer = Timer(duration, callback);
|
|
}
|
|
|
|
/// 立即执行待执行的回调(跳过防抖)
|
|
void flush() {
|
|
_timer?.cancel();
|
|
_timer = null;
|
|
}
|
|
|
|
/// 取消待执行的回调
|
|
void cancel() {
|
|
_timer?.cancel();
|
|
_timer = null;
|
|
}
|
|
|
|
/// 是否有待执行的回调
|
|
bool get isActive => _timer?.isActive ?? false;
|
|
|
|
/// 释放资源
|
|
void dispose() {
|
|
_timer?.cancel();
|
|
_timer = null;
|
|
}
|
|
}
|