我尝试布置一些小部件,包括一个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(),
]),
喜欢吗?
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