loads static method
- required String unitId,
- AdropBannerListener? listener,
Loads up to 5 banners with a single network request and returns them as ready-to-mount widgets. Do NOT call load on the returned widgets — they are already loaded (a second load would issue another network request).
The returned widgets are re-attachable: unmounting (e.g. a ListView recycling an off-screen item) only detaches the native view, and remounting re-binds it. The native banner lives until you call dispose on it — each returned widget owns a WebView (~5-15 MB), so dispose every one of them when the screen goes away, even those never mounted.
listener is shared by all returned banners; use the requestId entry
in the callback metadata (see requestId) to tell slots apart.
Throws a PlatformException whose code is an AdropErrorCode name
(e.g. ERROR_CODE_AD_NO_FILL when nothing filled).
Implementation
static Future<List<AdropBannerView>> loads({
required String unitId,
AdropBannerListener? listener,
}) async {
final requestIds = List.generate(maxLoadsBatch, (_) => nanoid());
final response =
await adropAdManager.invokeLoadsBanners(unitId, requestIds);
final map = response is Map ? response : const {};
final filledIds = (map['requestIds'] as List?)?.cast<String>() ?? const [];
final metas = map['ads'] as List? ?? const [];
final views = <AdropBannerView>[];
for (var i = 0; i < filledIds.length; i++) {
final view = AdropBannerView._preloaded(
unitId: unitId,
requestId: filledIds[i],
listener: listener,
);
adropAdManager.registerPreloadedBanner(
view, filledIds[i], i < metas.length ? metas[i] as Map? : null);
views.add(view);
}
return views;
}