findDebouncerWidget static method
Attempts to find the DebouncerState in a parent widget. context
should
be the BuildContext of a child widget to a Debouncer widget.
debouncerKey
is an optional key that can be used to find a specific
Debouncer widget if multiple parent Debouncers exist.
Implementation
static DebouncerState? findDebouncerWidget(
BuildContext context, {
String? debouncerKey,
}) {
// Get a debouncer state for the context passed in.
final el = _getDebouncerStateWidget(context);
DebouncerState? elToExecute;
if (el != null &&
debouncerKey != null &&
el.widget.debouncerKey == debouncerKey) {
// Set elToExecute to the current found value.
elToExecute = el;
} else if (el != null && debouncerKey == null) {
// Set elToExecute to the current found value.
elToExecute = el;
} else {
context.visitAncestorElements((parent) {
// We use a local variable to work nicely with the scope
final _el = _getDebouncerStateWidget(parent);
if (_el != null &&
debouncerKey != null &&
_el.widget.debouncerKey == debouncerKey) {
// Set elToExecute to the current found value.
elToExecute = _el;
return false;
} else if (_el != null && debouncerKey == null) {
// Set elToExecute to the current found value.
elToExecute = _el;
return false;
}
return true;
});
}
return elToExecute;
}