mirror of
https://github.com/wgh136/pixes.git
synced 2025-09-27 12:57:24 +00:00
Add auto complete. Close #24
This commit is contained in:
28
lib/utils/debounce.dart
Normal file
28
lib/utils/debounce.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ui';
|
||||
|
||||
class Debounce {
|
||||
final Duration delay;
|
||||
VoidCallback? _action;
|
||||
Timer? _timer;
|
||||
|
||||
Debounce({required this.delay});
|
||||
|
||||
void call(VoidCallback action) {
|
||||
_action = action;
|
||||
_timer?.cancel();
|
||||
_timer = Timer(delay, _execute);
|
||||
}
|
||||
|
||||
void _execute() {
|
||||
if (_action != null) {
|
||||
_action!();
|
||||
_action = null;
|
||||
}
|
||||
}
|
||||
|
||||
void cancel() {
|
||||
_timer?.cancel();
|
||||
_action = null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user