loadInterstitialAd static method

void loadInterstitialAd(
  1. String codeId, {
  2. required AdLoadAdCallback onAdLoad,
  3. required AdCallback onAdShow,
  4. required AdCallback onAdClick,
  5. required AdCallback onAdClose,
  6. required AdErrorCallback onAdError,
})

Implementation

static void loadInterstitialAd(String codeId,
    {required AdLoadAdCallback onAdLoad,
    required AdCallback onAdShow,
    required AdCallback onAdClick,
    required AdCallback onAdClose,
    required AdErrorCallback onAdError}) {
  MethodChannel _methodChannel = new MethodChannel("com.fusion.ad/method");
  String eventId = "loadInterstitialAd";
  _methodChannel.invokeMethod(
      "loadInterstitialAd", {"eventId": eventId, "codeId": codeId});

  EventChannel eventChannel =
      EventChannel("com.fusion.ad/msg_event_$eventId");
  eventChannel.receiveBroadcastStream().listen((event) {
    switch (event["event"]) {
      case "onAdLoad":
        onAdLoad.call(event["ecpm"]);
        break;
      case "onAdShow":
        onAdShow.call();
        break;
      case "onAdClick":
        onAdClick.call();
        break;
      case "onAdClose":
        onAdClose.call();
        break;
      case "onAdError":
        onAdError.call(event["code"], event["msg"]);
        break;
    }
  });
}