loads static method

Future<List<AdropNativeAd>> loads({
  1. required String unitId,
  2. bool useCustomClick = false,
  3. AdropNativeListener? listener,
})

Loads up to 5 native ads with a single network request. The returned instances are already loaded (isLoaded is true) — do NOT call load on them (a second load would issue another network request). Bind each to an AdropNativeAdView as usual; re-mounting a recycled list item re-binds the same instance.

Batch-loaded ads are always direct ads (isBackfilled is false) — the batch path intentionally skips the backfill fallback.

Every returned instance owns a native WebView (~5-15 MB): call dispose on each one when done, including instances never bound to a view.

Throws a PlatformException whose code is an AdropErrorCode name (e.g. ERROR_CODE_AD_NO_FILL when nothing filled).

Implementation

static Future<List<AdropNativeAd>> loads({
  required String unitId,
  bool useCustomClick = false,
  AdropNativeListener? listener,
}) async {
  final requestIds = List.generate(maxLoadsBatch, (_) => nanoid());
  final response =
      await _invokeChannel.invokeMethod(AdropMethod.loadsNative, {
    'unitId': unitId,
    'requestIds': requestIds,
    'useCustomClick': useCustomClick,
  });
  final map = response is Map ? response : const {};
  final filledIds = (map['requestIds'] as List?)?.cast<String>() ?? const [];
  final metas = map['ads'] as List? ?? const [];

  final ads = <AdropNativeAd>[];
  for (var i = 0; i < filledIds.length && i < metas.length; i++) {
    ads.add(AdropNativeAd._preloaded(
      unitId: unitId,
      requestId: filledIds[i],
      metadata: metas[i] as Map,
      useCustomClick: useCustomClick,
      listener: listener,
    ));
  }
  return ads;
}