AppFlowy/frontend/appflowy_flutter/lib/util/debounce.dart

25 lines
380 B
Dart
Raw Normal View History

2023-03-22 06:49:15 +00:00
import 'dart:async';
import 'package:flutter/material.dart';
class Debounce {
Debounce({
this.duration = const Duration(milliseconds: 1000),
});
final Duration duration;
Timer? _timer;
2023-03-22 06:49:15 +00:00
void call(VoidCallback action) {
dispose();
_timer = Timer(duration, () {
action();
});
}
void dispose() {
_timer?.cancel();
_timer = null;
}
}