gpt4 book ai didi

dart - flutter 位置固定等效

转载 作者:IT老高 更新时间:2023-10-28 12:35:00 26 4
gpt4 key购买 nike

是否可以在屏幕中修复一个无论滚动如何都保持固定的对象?

类似于 CSS 位置固定的东西。

最佳答案

您绝对可以定位 Stack 的子代使用 Positioned 的小部件小部件。

下面的最小示例将红色框放置在 ListView 上方,方法是将子项放置在 Stack 子项中的 ListView 之后的 Positioned 小部件中。

List<String> todos = [...];
return new Stack(
children: <Widget>[
new ListView(
children: todos
.map((todo) => new ListTile(title: new Text(todo)))
.toList(),
),
new Positioned(
left: 30.0,
top: 30.0,
child: new Container(
width: 100.0,
height: 80.0,
decoration: new BoxDecoration(color: Colors.red),
child: new Text('hello'),
)
),
],
);

这里它位于 Scaffold 主体内。如果您添加更多项目,您会发现列表滚动而不移动红色框。

an absolutely positioned example

关于dart - flutter 位置固定等效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49566752/

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