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',
    <String, dynamic>{
      'id': hashCode,
      'adId': adId,
      'totalDuration': totalDuration.inSeconds,
      'maxCount': maxCount,
    },
  );
  _channel = MethodChannel('$_INSTREAM_METHOD_CHANNEL/LOADER/$hashCode');
  _channel.setMethodCallHandler((MethodCall call) async {
    switch (call.method) {
      case 'onAdLoaded':
        List<int> ads = List<int>.from(call.arguments['ads']);
        List<InstreamAd> instreamAds = <InstreamAd>[];
        for (int adId in ads) {
          instreamAds.add(InstreamAd(id: adId));
        }
        onAdLoaded?.call(instreamAds);
        break;
      case 'onAdFailed':
        onAdFailed?.call(call.arguments['error_code']);
        break;
      default:
        throw UnimplementedError;
    }
    return;
  });
}