简体   繁体   中英

items in listview are not placed at the top of the scaffold container

I am building a dynamic scroll view. The current result is this one. 当前结果

The problem is that the items are not positioned on top at position 0, as I intended. 用红色突出显示:不打算在那里的额外空间。

I tried already placing the searchbar over the top extra space of the scroll view, but when you start scrolling, the cards are overlapping the searchbar widget.

So my question is: what is causing this extra space, and how can I remove it?

ScrollList class:

class ScrollListWidget extends DersObject {

  late ListHandler listHandler;

  int cardsPerScreen;
  double margin;

  double getCardHeight(){
    return this.height / this.cardsPerScreen - heightPercentageAsDouble(this.margin) * 2;
  }

  ScrollListWidget(width, height, listType, {this.cardsPerScreen = 3, this.margin = 0.01}): super(width: width, height: height){
    this.listHandler = ListHandler(width, getCardHeight(), listType);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        width: width,
        height: height,
        child: new Scaffold(
            body:  new ListView.separated
              (
                separatorBuilder: (BuildContext context, int index) {
                  return Line(height: heightPercentageAsDouble(this.margin), width: width,
                  color: Color.fromARGB(255, 255, 255, 255));
                },
                itemCount: listHandler.getList().length,
                itemBuilder: (BuildContext ctxt, int index) {
                  return listHandler.getList()[index];
                }
            )
        )
    );

  }

}

From documentation of ListView :

By default, ListView will automatically pad the list's scrollable extremities to avoid partial obstructions indicated by MediaQuery's padding. To avoid this behavior, override with a zero padding property.

So try to add this to the ListView constructor:

padding: EdgeInsets.zero,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM