-1

I have a CustomScrollView and bottomNavigationBar. The bottomNavigationBar disappears when I scroll up. This is configured via the below AnimatedContainer settings.

height: _bottombarisVisible ? 80 : 0,

Works fine except am encountering the below error.

A RenderFlex overflowed by 20 pixels on the bottom.

Please see entire Scaffold code below.

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

Thanks in advance.

2 Answers2

0

Figured it out.

For those encountering the same issue, resolved by reducing the AnimatedContainer duration.

duration: Duration(milliseconds: 10),

Not an optimal solution but works for me. If anyone has something better to recommend, please do so.

0

A better solution was to add either a sizedbox or SliverToBoxAdapter and adjust height to ensure list available is equal to the visible list screen height.