Flutter中带有ListView的FAN横幅



我正在创建一个使用Flutter的应用程序。该布局包括一个带有许多按钮的大型ListView和一个Facebook受众网络(FAN(横幅。我尝试了许多组合,以使横幅固定在屏幕底部。我还使用了脚手架下一个底部导航栏的方法,如下所述:[https://stackoverflow.com/questions/48934439/flutter-banner-ad-overlapping-the-main-screen][1]

问题是,我得到的是作为ListView中最后一项的横幅,除非用户向下滚动到ListView的最底部,否则它是不可见的(这不太可能发生(

有了底部的导航栏,我看不出有什么办法可以在上面加上FAN横幅。我不知道这是否可能。

我目前的布局是这样定义的:

class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
String FB_INTERSTITIAL_AD_ID =
"IMG_16_9_APP_INSTALL#2312433698835503_2650502525028617";
bool isInterstitialAdLoaded = false;
@override
void initState() {
FacebookAudienceNetwork.init(
testingId: "37b1da9d-b48c-4103-a393-2e095e734bd6", //optional
);
_loadInterstitialAd();
loadBannerAd();
_showInterstitialAd();
super.initState();
}
void _loadInterstitialAd() {
FacebookInterstitialAd.loadInterstitialAd(
placementId: FB_INTERSTITIAL_AD_ID,
listener: (result, value) {
if (result == InterstitialAdResult.LOADED) {
isInterstitialAdLoaded = true;
}
if (result == InterstitialAdResult.DISMISSED &&
value["invalidated"] == true) {
isInterstitialAdLoaded = false;
_loadInterstitialAd();
}
},
);
}
_showInterstitialAd() {
if (isInterstitialAdLoaded == true) {
FacebookInterstitialAd.showInterstitialAd();
} else {
print("Ad not loaded yet");
}
}
Widget _bannerAd = SizedBox(width: 0, height: 0);
void loadBannerAd() {
setState(() {
_bannerAd = FacebookBannerAd(
placementId: Platform.isAndroid
? "IMG_16_9_APP_INSTALL#2312433698835503_2964944860251047"
: "1330190004069862_13302241873XXXXX",
//placementId: "IMG_16_9_APP_INSTALL#2312433698835503_2964944860251047",
bannerSize: BannerSize.STANDARD,
listener: (result, value) {
print("$result == $value");
},
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Dictionary of Insurance"),
),
body: Center(
child: ListView(
children: <Widget>[
const SizedBox(height: 5),
Container(
color: Colors.transparent,
width: MediaQuery.of(context).size.width,
height: 60,
child: RaisedButton(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
},
color: Colors.blue[300],
child: Text(
"Accident",
style: TextStyle(
color: Colors.white,
fontFamily: 'Raleway',
fontSize: 22.0,
),
),
),
),
//////////////
// Lots of many other buttons similar to this one above
//////////////
FlatButton(
child: Text("Load Banner Ad"),
onPressed: () => loadBannerAd(),
),
FlatButton(
child: Text("Load Interstitial Ad"),
onPressed: () => _showInterstitialAd()),
Flexible(
child: Container(),
flex: 1,
fit: FlexFit.loose,
),
_bannerAd
],
),
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.business),
label: 'Business',
),
],
),
);
}
}

最后两个按钮取自一个关于如何将FAN与Flutter一起使用的示例,它们按预期工作。使用此布局时,横幅最初不可见,因为它是在ListView中的所有按钮之后绘制的。

你能帮我一下吗?

最后,我成功了。

简单地说,在底部导航栏中,我调用了_bannerAd,就这样!

import 'package:facebook_audience_network/facebook_audience_network.dart';
import 'package:flutter/material.dart';
import 'dart:io' show Platform;
import 'destination.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
String FB_INTERSTITIAL_AD_ID =
"IMG_16_9_APP_INSTALL#2312433698835503_2650502525028617";
bool isInterstitialAdLoaded = false;
@override
void initState() {
FacebookAudienceNetwork.init(
testingId: "37b1da9d-b48c-4103-a393-2e095e734bd6", //optional
);
_loadInterstitialAd();
loadBannerAd();
_showInterstitialAd();
super.initState();
}
void _loadInterstitialAd() {
FacebookInterstitialAd.loadInterstitialAd(
placementId: FB_INTERSTITIAL_AD_ID,
listener: (result, value) {
if (result == InterstitialAdResult.LOADED) {
isInterstitialAdLoaded = true;
}
if (result == InterstitialAdResult.DISMISSED &&
value["invalidated"] == true) {
isInterstitialAdLoaded = false;
_loadInterstitialAd();
}
},
);
}
_showInterstitialAd() {
if (isInterstitialAdLoaded == true) {
FacebookInterstitialAd.showInterstitialAd();
} else {
print("Ad not loaded yet");
}
}
Widget _bannerAd = SizedBox(width: 0, height: 0);
void loadBannerAd() {
setState(() {
_bannerAd = FacebookBannerAd(
placementId: Platform.isAndroid
? "IMG_16_9_APP_INSTALL#2312433698835503_2964944860251047"
: "1330190004069862_133022418739XXXX",
//placementId: "IMG_16_9_APP_INSTALL#2312433698835503_2964944860251047",
bannerSize: BannerSize.STANDARD,
listener: (result, value) {
print("$result == $value");
},
);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Dictionary of Insurance"),
),
body: Center(
child: ListView(
children: <Widget>[
const SizedBox(height: 5),
Container(
color: Colors.transparent,
width: MediaQuery.of(context).size.width,
height: 60,
child: RaisedButton(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
},
color: Colors.blue[300],
child: Text(
"Accident",
style: TextStyle(
color: Colors.white,
fontFamily: 'Raleway',
fontSize: 22.0,
),
),
),
),
//////////////
// Lots of many other buttons similar to this one above
//////////////
],
),
),
bottomNavigationBar: _bannerAd,
);
}
}

最新更新