Initial public commit

This commit is contained in:
Shawn
2022-08-29 20:38:28 -06:00
commit a1e1aa156f
708 changed files with 21643 additions and 0 deletions

View File

@ -0,0 +1,35 @@
import 'dart:async';
import 'package:flutter/material.dart';
class Throttler {
Throttler(this.interval);
final Duration interval;
VoidCallback? _action;
Timer? _timer;
void call(VoidCallback action, {bool immediateCall = true}) {
// Let the latest action override whatever was there before
_action = action;
// If no timer is running, we want to start one
if (_timer == null) {
// If immediateCall is true, we handle the action now
if (immediateCall) {
_callAction();
}
// Start a timer that will temporarily throttle subsequent calls, and eventually make a call to whatever _action is (if anything)
_timer = Timer(interval, _callAction);
}
}
void _callAction() {
_action?.call(); // If we have an action queued up, complete it.
_timer = null;
}
void reset() {
_action = null;
_timer = null;
}
}