AMPSNativeAd constructor

AMPSNativeAd({
  1. required AdOptions config,
  2. NativeType nativeType = NativeType.native,
  3. AMPSNativeAdListener? mCallBack,
  4. AMPSNativeRenderListener? mRenderCallBack,
  5. String? instanceId,
  6. bool mallMode = false,
  7. void onMallEvent(
    1. String adId,
    2. int code,
    3. Map<String, dynamic>? info
    )?,
})

Implementation

AMPSNativeAd({
  required this.config,
  this.nativeType = NativeType.native,
  this.mCallBack,
  this.mRenderCallBack,
  String? instanceId,
  this.mallMode = false,
  this.onMallEvent,
}) : instanceId = instanceId ?? _generateInstanceId() {
  if (mallMode && nativeType != NativeType.unified) {
    throw ArgumentError('Mall mode requires unified native ads');
  }
  final userData =
      mallMode || config.mallQuery != null || config.mallReward != null
          ? mallUserData(config)
          : null;
  final arguments = _wrapArgs({
    ...config.toMap(nativeType: nativeType),
    if (mallMode) 'mallMode': true,
    if (userData != null) 'gmMallUserData': userData,
  });
  NativeCallbackRouter.instance.register(this.instanceId, _handleCall);
  _creation = AdscopeSdk.invokeMethod(
    AMPSAdSdkMethodNames.nativeCreate,
    arguments,
  ).then<PlatformException?>((_) => null,
      onError: (Object error) => error is PlatformException
          ? error
          : PlatformException(code: 'CREATE_FAILED', message: '$error'));
}