AMPSNativeAd constructor
AMPSNativeAd({
- required AdOptions config,
- NativeType nativeType = NativeType.native,
- AMPSNativeAdListener? mCallBack,
- AMPSNativeRenderListener? mRenderCallBack,
- String? instanceId,
- bool mallMode = false,
- void onMallEvent()?,
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'));
}