我的应用底部有横幅广告。
在显示广告之前,我必须检查用户是否删除了广告。
花了一些时间,所以我检查了一下,然后调用 setState
来展示广告。
下面是我的小部件。
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
top: false,
left: true,
right: true,
bottom: true,
child: Scaffold(
body: DefaultTabController(
length: (_selectedIndex == 0)
? STR_TAB_TITLE_LIST.length
: _tabMyParameters().length,
child: NestedScrollView(
controller: scrollctr,
headerSliverBuilder: (BuildContext context,
bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
backgroundColor: Colors.white,
centerTitle: true,
pinned: true,
snap: true,
floating: true,
title: Image(
image: AssetImage(imgRootPath + "img_typelogo.png"),
width: 133.5,
height: 20,
),
leading: Builder(
builder: (context) =>
IconButton(
icon: Icon(icon),
iconSize: 17.0,
color: CC_GREYISH_BROWN,
onPressed: () =>
Scaffold.of(context).openDrawer())),
bottom: _selectedIndex == 0 ? TabBar(
isScrollable: true,
tabs: STR_TAB_TITLE_LIST.map((e) => Tab(text: e))
.toList(),
controller: _tabController,
)
: PreferredSize(
child: Container(
height: 0.0,
alignment: Alignment.centerLeft,
child: null
),
preferredSize: Size(MediaQuery
.of(context)
.size
.width, 0.0),
),
),
];
},
body: _selectedIndex == 0 ? TabBarView(
children: []..addAll(STR_TAB_TITLE_LIST.map((e) {
return TabPage(e);
})),
controller: _tabController,
) : _pages[_selectedIndex],
),
);,
drawer: Drawer(child: getDrawerMenuList(context, version)),
bottomNavigationBar: _getBottomNavigationBar(context),
),
),
);
}
_getBottomNavigationBar()
Widget _getBottomNavigationBar(BuildContext ctxt) {
if (removeAd != null) {
if(!removeAd) {
bannerAd = BannerAd(
adUnitId: AdManager.bannerAdUnitId,
size: AdSize.banner,
request: AdRequest(),
listener: AdListener(
onAdLoaded: (Ad ad) => print('Ad loaded.'),
onAdFailedToLoad: (Ad ad, LoadAdError error) {
print('Ad failed to load: $error');
dispose();
},
onAdOpened: (Ad ad) => print('Ad opened.'),
onAdClosed: (Ad ad) => print('Ad closed.'),
onApplicationExit: (Ad ad) => print('Left application.'),
)
);
bannerAd.load();
} else if (removeAd && bannerAd != null) {
bannerAd.dispose();
}
}
return AnimatedContainer(
duration: Duration(milliseconds: 1),
height: removeAd ? 60.0 : 60.0 + bannerAd.size.height.toDouble(),
decoration: BoxDecoration(
color: removeAd ? CC_SIDE_BG : Colors.black,
boxShadow: [
BoxShadow(
color: Colors.grey,
offset: Offset(0.0, 1.0), //(x,y)
blurRadius: 4.0,
)
]
),
child: Theme(
data: Theme.of(ctxt).copyWith(canvasColor: CC_SIDE_BG),
child: Column(
children: [
BottomNavigationBar(
onTap: (int index) {
setState(() {
_selectedIndex = index;
});
},
currentIndex: _selectedIndex,
items: <BottomNavigationBarItem>[],
),
removeAd ? Container()
: Container(
color: Colors.black,
alignment: Alignment.center,
child: AdWidget(ad: bannerAd),
width: bannerAd.size.width.toDouble(),
height: bannerAd.size.height.toDouble(),
)
],
),
)
);
}
removeAd 默认值为 true。
当它为false时,底部导航视图有几秒钟的黑色空白区域。
========编辑============
flutter 显示带有黄色和黑色条纹(?)的溢出区域,但我的应用程序没有显示条纹。
但错误不断显示。
+ 溢出的小部件是列
答案 0 :(得分:1)
使用 Container 使用扩展或固定高度。