showInterstitialAd static method

void showInterstitialAd(
  1. String unitId, {
  2. AdCallback? onAdLoad,
  3. AdCallback? onAdShow,
  4. AdCallback? onAdClick,
  5. AdCallback? onAdClose,
  6. AdErrorCallback? onError,
})

show interstitial ad

Implementation

static void showInterstitialAd(String unitId,
    {AdCallback? onAdLoad,
    AdCallback? onAdShow,
    AdCallback? onAdClick,
    AdCallback? onAdClose,
    AdErrorCallback? onError}) {
  int channelId = ++_channelId;
  _methodChannel.invokeMethod(
      "showInterstitialAd", {"_channelId": channelId, "unitId": unitId});

  Future.delayed(Duration(milliseconds: 100), () {
    EventChannel eventChannel = EventChannel("com.mob.adsdk/event_$channelId");
    eventChannel.receiveBroadcastStream().listen((event) {
      switch (event["event"]) {
        case "onAdLoad":
          onAdLoad?.call(event["id"]);
          break;

        case "onAdShow":
          onAdShow?.call(event["id"]);
          break;

        case "onAdClick":
          onAdClick?.call(event["id"]);
          break;

        case "onAdClose":
          onAdClose?.call(event["id"]);
          break;

        case "onError":
          onError?.call(event["id"], event["code"], event["message"]);
          break;
      }
    });
  });
}