loadNativeAd method

Future<StartAppNativeAd> loadNativeAd({
  1. StartAppAdPreferences prefs = const StartAppAdPreferences(),
  2. VoidCallback? onAdImpression,
  3. VoidCallback? onAdClicked,
})

Loads native ad, does not create an underlying native platform view.

Once loaded the native ad must be shown with StartAppNative. In opposite to banners, native ad can't be refreshed automatically. You must take care about interval of reloading native ads. Default interval for reloading banners is 45 seconds, which can be good for native ads as well. Make sure you don't load native ad too frequently, cause this may negatively impact your revenue.

IMPORTANT: You must not handle touch/click events from widgets of your native ad. Clicks are handled by underlying view, so make sure your buttons or other widgets doesn't intercept touch/click events.

Implementation

Future<StartAppNativeAd> loadNativeAd({
  StartAppAdPreferences prefs = const StartAppAdPreferences(),
  VoidCallback? onAdImpression,
  VoidCallback? onAdClicked,
}) {
  return _channel.invokeMethod('loadNativeAd', prefs._toMap()).then((value) {
    if (value is Map) {
      dynamic id = value['id'];

      if (id is int && id > 0) {
        if (onAdImpression != null) {
          onAdImpressionCallbacks[id] = onAdImpression;
        }

        if (onAdClicked != null) {
          onAdClickedCallbacks[id] = onAdClicked;
        }
        return StartAppNativeAd._(id, value.cast());
      }
    }

    throw StartAppException(message: value);
  });
}