gpt4 book ai didi

Flutter Positioned widget 导致错误 : Incorrect use of ParentDataWidget

转载 作者:行者123 更新时间:2023-12-01 23:58:26 26 4
gpt4 key购买 nike

以下代码导致错误:ParentDataWidget 的使用不正确。此错误的原因是 Positioned 小部件,但我不确定为什么...

return Scaffold(
body: Container(
color: Colors.red,
child: Positioned(
left: 32.0,
child: Container(
width: 128.0,
height: 128.0,
color: Colors.yellow,
),
),
),
);

最佳答案

Positioned 必须根据 documentationStack 中就是说

A widget that controls where a child of a Stack is positioned.

A Positioned widget must be a descendant of a Stack, and the path from the Positioned widget to its enclosing Stack must contain only StatelessWidgets or StatefulWidgets (not other kinds of widgets, like RenderObjectWidgets).

return Scaffold(
body: Container(
color: Colors.red,
child: Stack(
children: <Widget>[
Positioned(
left: 32.0,
child: Container(
width: 128.0,
height: 128.0,
color: Colors.yellow,
),
),
],
),
),
);

关于Flutter Positioned widget 导致错误 : Incorrect use of ParentDataWidget,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62266850/

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