首页 > 解决方案 > Flutter A RenderFlex 底部溢出 46 像素

问题描述

我的应用底部有横幅广告。在我展示广告之前,我必须检查用户是否删除了广告。花了一点时间,所以我检查并打电话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。
当它为假时,底部导航视图有几秒钟的黑色空白区域。

========EDIT===========
颤动显示溢出区域带有黄色和黑色条纹(?)但我的应用程序没有显示条纹的东西。
但错误不断显示。

+ 溢出的小部件是列

标签: flutterdart

解决方案


使用 Container 使用扩展或固定高度。


推荐阅读