视频流广告
视频流广告
此章节将演示如何请求在Flutter
环境下请求与展示视频流广告
引入组件
引入ZJDrawAdView
组件即可请求信息流广告,需要在drawAdListener
回调中处理事件
/// 视频流广告视图
class ZJDrawAdView extends StatelessWidget {
/// 广告位ID
final String posId;
/// 视频类型素材的声音开关
final bool videoSoundEnable;
/// 宽
final double width;
/// 高
final double height;
/// 回调
final Function(ZJEvent ret)? drawAdListener;
const ZJDrawAdView(this.posId,
{Key? key,
required this.width,
required this.height,
this.videoSoundEnable = true,
this.drawAdListener})
: super(key: key);
}
视频流广告回调说明
ret.action | 说明 |
---|---|
ZJEventAction.onAdError | 广告展示失败 ret.code:错误码,非错误事件为0 ret.msg:错误信息,非错误事件为空字符串 |
ZJEventAction.onAdShow | 广告展示成功 |
ZJEventAction.onAdClick | 广告点击 |
ZJEventAction.onAdClose | 广告关闭 |
接入示例
example/lib/ad/draw_ad.dart
child: ZJDrawAdView(
// 广告位ID
posId,
width: double.infinity,
height: double.infinity,
drawAdListener: (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
}
},
),