gpt4 book ai didi

flutter - 为 Sliver child 设置自定义高度

转载 作者:IT王子 更新时间:2023-10-29 07:18:07 28 4
gpt4 key购买 nike

在下面的代码中我遇到了问题,我正在尝试为 Sliver child 的每个 child 设置自定义高度,我刚刚在 Flutter 上了解了这个小部件,我想修复它,例如:

CustomScrollView(
slivers: <Widget>[
SliverFixedExtentList(
itemExtent: MediaQuery.of(context).size.height,
delegate: SliverChildListDelegate([
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: 50.0,
minHeight: 50.0
),
child: Text('dddddddddd'),
),
PageView(
children: <Widget>[
Container(color: Colors.green, child: Center(child: Text("Page 1"))),
Container(color: Colors.red, child: Center(child: Text("Page 2"))),
Container(color: Colors.indigo, child: Center(child: Text("Page 3"))),
],
),
]),
),
],
),

Text 小部件应该有 50.0 大小,但 itemExtent 避免这样,当我为 itemExtent 设置一些高度时所有 child 的高度继承自那个

最佳答案

顾名思义 - itemExtent: 它为每个 child 提供高度。

您可以简单地使用 SliverList 并为每个 child 指定特定的高度。

CustomScrollView(
slivers: <Widget>[
SliverList(
delegate: SliverChildListDelegate([
ConstrainedBox(
constraints: BoxConstraints(maxHeight: 50.0, minHeight: 50.0),
child: Center(child: Text('Child 1')),
),
SizedBox(
height: 200.0,
child: PageView(
children: <Widget>[
Container(
color: Colors.green,
child: Center(child: Text("Page 1"))),
Container(
color: Colors.red,
child: Center(child: Text("Page 2"))),
Container(
color: Colors.indigo,
child: Center(child: Text("Page 3"))),
],
),
),
]),
),
],
),

输出: enter image description here

关于flutter - 为 Sliver child 设置自定义高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56681813/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com