gpt4 book ai didi

flutter - 定位的小部件必须直接放置在 Stack 小部件内

转载 作者:IT王子 更新时间:2023-10-29 06:51:53 25 4
gpt4 key购买 nike

我正在尝试实现带有图像和其中文本的 gridview。我想要黑色背景图像底部的文本。这是我的 ListItem

代码
class ListItem extends StatelessWidget {
String url;
String name;

ListItem(this.url, this.name);
@override
Widget build(BuildContext context) {

return new Container(
child: new Column(
children: <Widget>[
new Image.network('${url}', fit: BoxFit.cover),
new Positioned(
child: new Container(
child: new Text('${name}',
style: new TextStyle(fontSize: 20.0, color: Colors.white)),
decoration: new BoxDecoration(color: Colors.black),
padding: new EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 16.0)),
left: 0.0,
bottom: 108.0,
)
],
));
}
}

这段代码显示错误

Positioned widgets must be placed directly inside Stack widgets.
Positioned(no depth, dirty) has a Stack ancestor, but there are other widgets between them:
- Column(direction: vertical, mainAxisAlignment: start, crossAxisAlignment: center)

最佳答案

问题出在 Column 上,在这里和那里更改了几行后,我终于发现这是因为 Column

一旦我将 Column 更改为 Stack,它就可以正常工作。

return new Container(
child: new Stack(

关于flutter - 定位的小部件必须直接放置在 Stack 小部件内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50485467/

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