0

I have banner ad to bottom of my app. Before I display ad, I have to check if user removed ad. It took a bit time so I check it and call setState to show ad.

It's my widget below.

@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), ), ), ); } 

The _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(), ) ], ), ) ); } 

The removeAd default value is true.
When it was false, the bottom navigation view has black empty area for seconds.

========EDIT===========
flutter shows overflowed area with yellow and black stripes(?) but My app not showing the stripes thing.
but error keep showing.

+ the overflowed widget is column

1 Answer 1

1

Use Expanded or fixed height using Container.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.