loadNativeAd method

  1. @override
Future<OcmNativeAd> loadNativeAd({
  1. required String prebidConfigId,
  2. String? gamAdUnitId,
  3. String? gamNativeFormatId,
  4. OcmNativeLoadMode mode = OcmNativeLoadMode.gam,
  5. OcmNativeListener? listener,
})
override

Implementation

@override
Future<OcmNativeAd> loadNativeAd({
  required String prebidConfigId,
  String? gamAdUnitId,
  String? gamNativeFormatId,
  OcmNativeLoadMode mode = OcmNativeLoadMode.gam,
  OcmNativeListener? listener,
}) async {
  final adId = 'native-${DateTime.now().microsecondsSinceEpoch}';
  if (listener != null) {
    _nativeListeners[adId] = listener;
  }
  try {
    final map = await methodChannel.invokeMapMethod<Object?, Object?>(
      'native.load',
      <String, Object?>{
        'adId': adId,
        'prebidConfigId': prebidConfigId,
        'gamAdUnitId': gamAdUnitId,
        'gamNativeFormatId': gamNativeFormatId,
        'mode': mode.name,
      },
    );
    return OcmNativeAd.fromMap(map ?? <Object?, Object?>{});
  } finally {
    _nativeListeners.remove(adId);
  }
}