首页 > 解决方案 > Problem in body height in SlidingUpPanel flutter

问题描述

Not all list are visible in body under SlideUpPanel

In list I am having 83 items but last 2~3 items are not visible

enter image description here

SlidingUpPanel(
    minHeight: 50,
    body: Container(
            height: MediaQuery.of(context).size.height-100, //No effect
            child: ListView.builder(
                itemCount: dataBox.values.length,
                itemBuilder: (context, i){
                    return ListTile(...);
                }
            )
        ),
    panel: Container(
        color: Colors.black,
    ),
)

标签: androidflutterdart

解决方案


If you go into the source code of SlidingUpPanel, you can see that it is using the screen size to set the width and height of the body:

// Inside SlidingUpPanel's build() method:

// ... other lines
child: Container(
           height: MediaQuery.of(context).size.height,
           width: MediaQuery.of(context).size.width,
           child: widget.body,
       ),
// ... other lines

This is why when you add an AppBar and other elements in the screen, it will reposition the body but the body's height is still equal to the screen height. One workaround is to use a Stack instead of setting the body of the SlidingUpPanel. Something like:

@override
build(context) {
    var _collapsedHeight = 50.0;
    return Stack(
      children: [
        Container(
            // Set the padding to display above the panel
            padding: EdgeInsets.only(bottom: _collapsedHeight),
            child: ListView.builder(
                itemCount: dataBox.values.length,
                itemBuilder: (context, i){
                  return ListTile(...);
                }
            )
        ),
        SlidingUpPanel(
          minHeight: _collapsedHeight,
          panel: Container(
            color: Colors.black,
          ),
        ),
     ],
  );
}

推荐阅读