ListView变大

问题描述 投票:1回答:1

我尝试布置一些小部件,包括一个ListView。我希望ListView填充可用空间。如果ListView内容较大,则应可滚动。此刻ListView太大,窗口小部件逐渐超出屏幕。

...
body: Column(mainAxisAlignment: MainAxisAlignment.start, children: [
        Card(
          child: Padding(
            padding: const EdgeInsets.all(2.0),
            child: Column(children: [
              Text('Text'),
              ListView.builder(
                shrinkWrap: true,
                physics: ClampingScrollPhysics(),
                itemBuilder: (BuildContext context, int index) => actionWidgetList[index],
                itemCount: actionList.length,
              ),
            ]),
          ),
        ),
        rangeInitialized
            ? Container(
                alignment: Alignment.bottomCenter,
                width: MediaQuery.of(context).size.width,
                height: MediaQuery.of(context).size.width,
                child: another.widget,
              )
            : SizedBox(),
      ]),
flutter flutter-layout
1个回答
0
投票

喜欢吗?

SingleChildScrollView(
  child: Column(mainAxisAlignment: MainAxisAlignment.start, children: [
    Card(
      child: Padding(
        padding: const EdgeInsets.all(2.0),
        child: Column(children: [
          Text('Text'),
          ListView.builder(
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),
            itemBuilder: (BuildContext context, int index) =>
                actionWidgetList[index],
            itemCount: actionList.length,
          ),
        ]),
      ),
    ),
    rangeInitialized
        ? Container(
            alignment: Alignment.bottomCenter,
            width: MediaQuery.of(context).size.width,
            height: MediaQuery.of(context).size.width,
            child: another.widget,
          )
        : SizedBox(),
  ]),

P.s。但是您需要知道SingleScrollView会渲染所有内容,而不仅仅是屏幕视图中的内容。因此,如果actionWidgetList太长,可能会降低性能,因此最好将根Column Widget和ListView更改为Slivers

© www.soinside.com 2019 - 2024. All rights reserved.