app-starlock/lib/tools/debounce_throttle_tool.dart
Liuyf 50257a7ffe fix: 1.优化上报逻辑,防止一样的token重复上报
2.请求头添加deviceId,为后续设备管理业务预留数据
2025-02-26 19:10:15 +08:00

24 lines
438 B
Dart

import 'dart:async';
import 'package:flutter/widgets.dart';
class DebounceThrottleTool<T> {
DebounceThrottleTool(this._debounceTime, this._callback);
Timer? _timer;
final Duration _debounceTime;
final void Function(T param) _callback;
void trigger(T param) {
_timer?.cancel();
_timer = Timer(_debounceTime, () {
_callback(param);
_timer = null;
});
}
void cancel() {
_timer?.cancel();
}
}