class Debounce {
  // 设定的时间间隔，单位为毫秒
  final int debounceTime;

  // 记录上次点击的时间
  DateTime? _lastClickTime;

  Debounce({this.debounceTime = 300});

  // 点击事件处理方法
  void onClick(Function action) {
    DateTime now = DateTime.now();
    if (_lastClickTime == null ||
        now.difference(_lastClickTime!) >
            Duration(milliseconds: debounceTime)) {
      _lastClickTime = now;
      action();
    }
  }
}
