InstreamAdLoader constructor

InstreamAdLoader({
  1. required String adId,
  2. required Duration totalDuration,
  3. int? maxCount,
  4. dynamic onAdLoaded(
    1. List<InstreamAd>
    )?,
  5. dynamic onAdFailed(
    1. int? errorCode
    )?,
})

Implementation

InstreamAdLoader({
  required this.adId,
  required this.totalDuration,
  this.maxCount,
  this.onAdLoaded,
  this.onAdFailed,
}) {
  Ads.instance.channelInstream.invokeMethod(
    "initInstreamLoader",
    {
      "id": hashCode,
      "adId": adId,
      "totalDuration": totalDuration.inSeconds,
      "maxCount": maxCount,
    },
  );
  _channel = MethodChannel("$INSTREAM_METHOD_CHANNEL/LOADER/$hashCode");
  _channel.setMethodCallHandler((call) async {
    switch (call.method) {
      case "onAdLoaded":
        List<int> ads = List<int>.from(call.arguments["ads"]);
        List<InstreamAd> instreamAds = [];
        ads.forEach((adId) {
          instreamAds.add(InstreamAd(id: adId));
        });
        onAdLoaded?.call(instreamAds);
        break;
      case "onAdFailed":
        onAdFailed?.call(call.arguments["error_code"]);
        break;
      default:
        throw UnimplementedError;
    }
    return;
  });
}