Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
381 views
in Technique[技术] by (71.8m points)

android - 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,
    ),
)
question from:https://stackoverflow.com/questions/65930946/problem-in-body-height-in-slidinguppanel-flutter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...