⚡ 高级功能
2.0: 对应 2.0.0 新契约。pub.dev 当前仍提供 1.0.3;依赖尚未升级时请切换到 1.x 文档。
事件与错误
late final StreamSubscription<AdEvent> subscription;
subscription = GromoreAds.events.listen((event) {
switch (event.type) {
case AdEventType.rewarded:
final reward = event.reward;
if (reward?.verified == true) grantReward(reward!);
case AdEventType.failed:
reportAdError(event.error);
default:
break;
}
});
await subscription.cancel();AdEvent 提供 AdEventType、AdFormat、placementId、requestId、viewId、adId、AdError、AdReward 和 AdEcpmInfo。事件覆盖请求、缓存、渲染、展示、点击、视频、奖励、Dislike、关闭和销毁。
厂商新增的未知 action 不会终止事件流,而是映射为 AdEventType.unknown,原始值保存在 rawAction 与 rawData。
MethodChannel 失败统一转换为 GromoreException:
try {
await handle.show();
} on GromoreException catch (error) {
log(error.code, error.subCode, error.message, error.requestId, error.details);
}