信息流广告
信息流广告
此章节将演示如何请求在Flutter
环境下请求与展示信息流广告
提示
Demo工程的测试广告位宽高比动态变化,实际配置的正式广告位宽高比固定
引入组件
引入ZJNativeExpressView
组件即可请求信息流广告,需要在nativeExpressListener
回调中处理事件
/// 信息流广告视图
class ZJNativeExpressView extends StatelessWidget {
/// 广告位ID
final String posId;
/// 视频类型素材的声音开关
final bool videoSoundEnable;
/// 宽
final double width;
/// 高
final double height;
/// 回调
final Function(ZJEvent ret)? nativeExpressListener;
const ZJNativeExpressView(this.posId,
{Key? key,
required this.width,
required this.height,
this.videoSoundEnable = false,
this.nativeExpressListener})
: super(key: key);
}
信息流广告回调说明
ret.action | 说明 |
---|---|
ZJEventAction.onAdError | 广告展示失败 ret.code:错误码,非错误事件为0 ret.msg:错误信息,非错误事件为空字符串 |
ZJEventAction.onAdShow | 广告展示成功 |
ZJEventAction.onAdClick | 广告点击 |
ZJEventAction.onAdClose | 广告关闭 |
接入示例
example/lib/ad/native_express.dart
child: ZJNativeExpressView(
// 广告位ID
posId,
width: double.infinity,
// 需要指定高度
height: 280,
nativeExpressListener: (ret) {
switch (ret.action) {
// 广告错误
case ZJEventAction.onAdError:
Fluttertoast.showToast(msg: "信息流错误:${ret.msg}");
if (kDebugMode) {
print("${ret.action}:${ret.code}-${ret.msg}");
}
break;
// 展示成功
case ZJEventAction.onAdShow:
Fluttertoast.showToast(msg: "信息流展示");
break;
// 点击广告
case ZJEventAction.onAdClick:
Fluttertoast.showToast(msg: "信息流点击");
break;
// 关闭
case ZJEventAction.onAdClose:
Fluttertoast.showToast(msg: "信息流关闭");
break;
default:
// ignore
}
},
),