-1

我有一个 CustomScrollView 和 bottomNavigationBar。当我向上滚动时,bottomNavigationBar 消失了。这是通过以下 AnimatedContainer 设置进行配置的。

高度:_bottombarisVisible ?80 : 0,

工作正常,除了遇到以下错误。

一个 RenderFlex 在底部溢出了 20 个像素。

请参阅下面的整个 Scaffold 代码。

@override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: Container(
        //height: MediaQuery.of(context).size.height - 50,
        child: CustomScrollView(
          controller: _hideButtonController,
          slivers: <Widget>[
            _doSearch
                ? SliverAppBar(
              flexibleSpace: FlexibleSpaceBar(
                title: Container(
                  width: 170,
                  child: TextField(
                    style: GoogleFonts.sourceSansPro(
                      textStyle: TextStyle(
                          fontSize: 18,
                          color: Color.fromRGBO(34, 34, 34, 1.0),
                          fontWeight: FontWeight.w600
                      ),
                    ),
                    controller: _searchcontroller,
                    decoration: const InputDecoration(
                      contentPadding: EdgeInsets.only(top:20),
                      enabledBorder: InputBorder.none,
                      focusedBorder: InputBorder.none,
                      //contentPadding: EdgeInsets.only(left: 9),
                      hintText: 'Search',
                      hintStyle: TextStyle(fontSize: 16, color: Color.fromRGBO(255, 255, 255, 1.0),fontWeight: FontWeight.w400),
                    ),
                  ),
                ),
              ),
              leading: IconButton(
                icon: Icon(Icons.close),
                color: Color.fromRGBO(34, 34, 34, 1),
                onPressed: () async {
                  setState(() {
                    _doSearch = false;
                  });
                },
              ),
              backgroundColor: Color.fromRGBO(255,255,255,1),
              floating: true,
              pinned: false,
              actions: [
                Builder(
                  builder: (context) => RaisedButton(
                      color: Colors.orange,
                      child: Text('Find ',
                        style: GoogleFonts.sourceSansPro(
                          color: Colors.white,
                          textStyle: TextStyle(
                              fontSize: 23,
                              color: Color.fromRGBO(6, 57, 143, 1),
                              fontWeight: FontWeight.w600
                          ),
                        ),
                        textAlign: TextAlign.left,
                      ),
                      onPressed: () async {
                        var mysearchwordsText = ((mysearchwords.text).trim()).toString();
                        if(mysearchwordsText!=''){
                          var glist = await getSearchData(gd,mysearchwordsText);
                          if(glist.length!=0){}
                        }
                      }
                  ),
                ),
              ],
            )
                : SliverAppBar(
              elevation: 0,
              flexibleSpace: FlexibleSpaceBar(
                title: Text(title,
                  style: GoogleFonts.sourceSansPro(
                    textStyle: TextStyle(
                        fontSize: 23,
                        color: Colors.orange,
                        fontWeight: FontWeight.w400
                    ),
                  ),
                  textAlign: TextAlign.left,
                ),
              ),
              leading: IconButton(
                icon: Icon(Icons.arrow_back_sharp),
                color: Colors.orange,
                onPressed: () async {
                  Navigator.pop(context);
                },
              ),
              backgroundColor: Colors.white,
              floating: true,
              pinned: false,
              actions: [
                IconButton(icon: Icon(Icons.search),
                    color: Colors.orange,
                    onPressed: (){
                      setState(() {
                        _doSearch = true;
                      });
                    })
              ],
            ),

            SliverToBoxAdapter(
            ),
            SliverList(
              delegate: SliverChildBuilderDelegate(
                    (context, index) {
                  final item = gd[index];
                  return GestureDetector(
                    onTap: () async =>  {
                      myitem = itemToString(item),
                      //log("myitem is: $myitem"),
                      Navigator.push(context, MyItemAnimatedRoute(
                        routeName: GroceryItemClassView,
                        page: GroceryItemClass(mydata: myitem),
                      )
                      ).then(refreshPage)
                    },
                    child: Card(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: [
                          item.buildname(context),
                          item.buildpriceandsize(context),
                          item.buildpic(context,item.pid),
                        ],
                      ),
                    ),
                  );
                },
                childCount: gd == null ? 0 : gd.length,
              ),
            ),
          ],

          //itemExtent: 200.0,
          // Let the ListView know how many items it needs to build.

        ),
      ),
      bottomNavigationBar: Builder(builder: (context) => _cartcount
          ? AnimatedContainer(
          duration: Duration(milliseconds: 200),
          height: _bottombarisVisible ? 80 : 0,
          child: BottomNavigationBar(
            backgroundColor: Colors.white,
            selectedItemColor: Colors.black87,
            unselectedItemColor: Colors.black87,
            items: [
              BottomNavigationBarItem(
                label: 'Cart',
                icon: Badge(
                  badgeColor: Colors.white,
                  shape: BadgeShape.circle,
                  borderRadius: BorderRadius.circular(8),
                  animationType: BadgeAnimationType.scale,
                  badgeContent: Container(
                    height: 20,
                    width: 20,
                    child: Text(mycartcount.toString(),
                      textAlign: TextAlign.center,
                    ),
                    decoration:
                    BoxDecoration(shape: BoxShape.circle, color: Colors.blue),
                  ),
                  child: IconButton(icon: Icon(Icons.shopping_cart),
                      color: Colors.orange,
                      onPressed: () async {
                        var mycart = await Myfunctions().getCartfromDB();
                        if(mycart!=null){
                          //Navigator.pushNamed(context, MyCartView, arguments: mycart).then(refreshPage);
                        }
                      }),
                ),
              ),
              BottomNavigationBarItem(
                label: 'Home',
                icon: IconButton(icon: Icon(Icons.home),
                    color: Colors.orange,
                    onPressed: () async {
                      Navigator.pop(context);
                    }),
              ),
            ],
          )
      )
          : Container()
      ),
      //bottomNavigationBar: BottomMenuWidget().bottommenuwidget(context,mycartcount),
    );

提前致谢。

4

2 回答 2

0

更好的解决方案是添加 sizedbox 或 SliverToBoxAdapter 并调整高度以确保可用列表等于可见列表屏幕高度。

于 2021-06-09T11:43:12.317 回答
0

弄清楚了。

对于那些遇到相同问题的人,可以通过减少 AnimatedContainer 持续时间来解决。

持续时间:持续时间(毫秒:10),

不是最佳解决方案,但对我有用。如果有人有更好的推荐,请这样做。

于 2021-03-11T06:18:40.227 回答