initial
This commit is contained in:
25
lib/utils/callback_debouncer.dart
Normal file
25
lib/utils/callback_debouncer.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class CallbackDebouncer {
|
||||
CallbackDebouncer(this._delay);
|
||||
|
||||
final Duration _delay;
|
||||
Timer? _timer;
|
||||
|
||||
/// Calls the given [callback] after the given duration has passed.
|
||||
void call(VoidCallback callback) {
|
||||
if (_delay == Duration.zero) {
|
||||
callback();
|
||||
} else {
|
||||
_timer?.cancel();
|
||||
_timer = Timer(_delay, callback);
|
||||
}
|
||||
}
|
||||
|
||||
/// Stops any running timers and disposes this instance.
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user