flutter - 如何在 Flutter Web 中插入 Adsense 展示广告
问题描述
我制作了一个 320px *60px 的固定展示广告。如何在我想要的地方插入颤振网页?这是我从 AdSense 获得的代码:
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- MyAd -->
<ins class="adsbygoogle"
style="display:inline-block;width:320px;height:60px"
data-ad-client="xxxxxxxxx"
data-ad-slot="xxxxxxxx"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
或者是否可以通过某种方式操纵 flt-glass-pane 使颤动不占据屏幕底部 60 像素并在那里插入 adsense 广告?
我正在寻找一种将 adsense 广告插入内置于 flutter-web 的移动网站的方法
解决方案
我能够将广告插入到 flutter-web 中的列表视图中,如下所示: 创建了一个 html 文件 adview.html
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
style="display:inline-block;width:320px;height:80px"
data-ad-client="ca-pub-xxxxxx"
data-ad-slot="xxxxxxx"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
然后,使用 html 的 IFrameElement:
// ignore: avoid_web_libraries_in_flutter
import 'dart:html';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
Widget adsenseAdsView() {
// ignore: undefined_prefixed_name
ui.platformViewRegistry.registerViewFactory(
'adViewType',
(int viewID) => IFrameElement()
..width = '320'
..height = '100'
..src = 'adview.html'
..style.border = 'none');
return SizedBox(
height: 100.0,
width: 320.0,
child: HtmlElementView(
viewType: 'adViewType',
),
);
}
然后我们可以从函数 adsenseAdsView() 中将小部件添加到我们想要的任何地方。我在 ListView 中添加了它。
推荐阅读
- python - 如何在 Y 轴的不同高度上绘制列表列表?
- angular - Angular 7 Firebase 电子邮件登录身份验证不起作用
- python-3.x - 将来自 HIVE 和 Hbase 的数据公开为 REST API - Hadoop Datalake - Python Pyspark
- javascript - 为什么这个 vue 组件在 Laravel 中不起作用
- c++ - 我的结构是一个单词列表,之后必须输出。但是输出格式不对
- html - 添加四个带有迷你边框线的块
- jquery - 引导事件仅在有条件的情况下触发?
- sql - 如何为满足条件的每一行替换“暂存”表中的值?
- css - 使 CSS 变量中指定的颜色变暗
- python - Python 链式`yield form`