load method

Future<void> load(
  1. DropdownItemLoader<T> loader, {
  2. bool replace = false,
  3. bool onException(
    1. Object
    )?,
})

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();
    }
  }
}