load method
Load the items from the given loader, and set the items to the dropdown menu.
The loaded items would replace the current items if replace
is true;
otherwise, the loaded items would be merged with the current items.
if onException
is provided, it would be called when an exception is thrown during the loading.
Implementation
Future<void> load(
DropdownItemLoader<T> loader, {
bool replace = false,
bool Function(Object)? onException,
}) async {
_clearHistory();
markAsLoading();
bool shouldMarkAsLoaded = true;
try {
final items = await loader();
setItems(items, replace: replace, rebuild: false);
} catch (e) {
shouldMarkAsLoaded = onException?.call(e) ?? true;
} finally {
if (shouldMarkAsLoaded) {
markAsLoaded();
}
}
}