AppFlowy/frontend/appflowy_flutter/lib/util/debounce.dart
Mathias Mogensen acc03b8cc4
chore: code cleanup according to unintroduced lints (#4488)
* chore: remove redundant arguments

* chore: remove unused constructor params

* chore: reorganize constructors

* chore: remove unnecessary awaits in returns

* chore: remove unnecessary paranthesis

* chore: add lints

* chore: clean up after merge

* chore: add sort constructors first

* chore: organize constructors in blocs

* chore: use sizedbox.shrink over empty container
2024-01-25 23:37:36 +08:00

25 lines
380 B
Dart

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