有人可以指出我在整合admob方面的正确方向吗?
我能够获得插件https://pub.dev/packages/ads的展示广告,但是当用户更改窗口小部件时,我无法获得该插件来卸载广告。
有人知道该怎么做吗?
class SecondRoute extends StatelessWidget {
final article;
Ads appAds;
final String appId = "ca-app-pub-4999865903647931~XXXXXXXXXX";
final String bannerUnitId = "ca-app-pub-4999865903647931/XXXXXXXxX";
// In the constructor, require a Todo.
SecondRoute({Key key, @required this.article}) : super(key: key);
@override
Widget build(BuildContext context) {
appAds = Ads(
appId,
bannerUnitId: bannerUnitId,
// screenUnitId: screenUnitId,
// keywords: <String>['ibm', 'computers'],
// contentUrl: 'http://www.ibm.com',
//childDirected: false,
testDevices: ['SM_A305YN:5554'],
testing: true,
listener: eventListener,
);
appAds.showBannerAd(anchorType: AnchorType.top, anchorOffset: 120);
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.redAccent,
title: Text(article['title']),
leading: new IconButton(
icon: new Icon(Icons.arrow_back),
onPressed: (){
appAds.hideBannerAd();
}
),
),
body: Center(
child: Container(
margin: const EdgeInsets.only(top: 40.0),
child: new SingleChildScrollView(
child: Card(
child: new Container(
padding: new EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
Image.network(article['image'], fit: BoxFit.fitWidth),
Html(data: article['content']),
]
),
),
),
),
)
)
);
}
}
我希望当用户点击“后退”按钮时,它会删除appAds标语。
答案 0 :(得分:1)
创建一个有状态的小部件而不是无状态的小部件,并在您要停止广告时调用dispose方法。
_ads?.dispose()