18 lines
305 B
Dart
18 lines
305 B
Dart
|
import 'dart:async';
|
||
|
|
||
|
class Debouncer {
|
||
|
final Duration delay;
|
||
|
Timer? _timer;
|
||
|
|
||
|
Debouncer({this.delay = const Duration(milliseconds: 300)});
|
||
|
|
||
|
run(void Function() action) {
|
||
|
_timer?.cancel();
|
||
|
_timer = Timer(delay, action);
|
||
|
}
|
||
|
|
||
|
void dispose() {
|
||
|
_timer?.cancel();
|
||
|
_timer = null;
|
||
|
}
|
||
|
}
|