gpt4 book ai didi

flutter - 错误使用 ParentDataWidget。 flutter

转载 作者:行者123 更新时间:2023-12-04 03:56:21 25 4
gpt4 key购买 nike

Anyne 知道这个错误是什么吗?我认为有些 child 不能放在什么东西里面?

接收到不兼容父数据的 RenderObject 的所有权链是:_GestureSemantics ← RawGestureDetector ← GestureDetector ← Expanded ← ColoredBox ← Container ← Padding ← ColoredBox ← ConstrainedBox ← Container ← ⋯

Container(
height: 35,
width: 150,
color: Colors.blueGrey,
child: Row(
children: [
Container(
width: 35,
height: double.infinity,
color: Colors.blue,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.black,
child: Expanded(
child: GestureDetector(
onTap: () {
setState(() {
intAmount = int.parse(amount);
intAmount--;
amount = intAmount.toString();
print(intAmount);
});
},
child: SizedBox(
child: Image(
image:
AssetImage('images/plus.png'),
),
),
),
),
),
),
),
Expanded(
child: Container(
height: double.infinity,
color: Colors.black,
child: Center(
child: GestureDetector(
onTap: () {},
child: Text(
'$intAmount',
style: TextStyle(
color: Colors.amber,
),
),
),
),
),
),
Container(
width: 35,
height: double.infinity,
color: Colors.orange,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.black,
child: GestureDetector(
onTap: () {
setState(() {
intAmount = int.parse(amount);
intAmount++;
amount = intAmount.toString();
print(intAmount);
});
//*********************************** */
},
child: Expanded(
child: SizedBox(
child: Image(
image: AssetImage(
'images/minus.png'),
),
),
),
),
),
),
)
],
),
)

最佳答案

我已经更新了你的代码,问题是你不能在 child 中使用 Expand,这意味着 Expanded 小部件必须是后代或父级

例子:

 Expanded(
child: MyWidget(),
),

Row(
children: [
Expanded(
child: MyWidget(),
),
Expanded(
child:Text("Text Widget"),
),
],
)

在列中

Column(
children: [
Expanded(
child: MyWidget(),
),
Expanded(
child:Text("Text Widget"),
),
],
),

不是这样的

Container(
child: Expanded(
child: MyWidget(),
),
)

您的更新代码

Column(
children: <Widget>[
Container(
height: 35,
width: 150,
color: Colors.blueGrey,
child: Row(
children: [
Container(
width: 35,
height: double.infinity,
color: Colors.blue,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.black,
child: GestureDetector(
onTap: () {
setState(() {
intAmount = int.parse(amount);
intAmount--;
amount = intAmount.toString();
print(intAmount);
});
},
child: SizedBox(
child: Image(
image: AssetImage('images/plus.png'),
),
),
),
),
),
),
Expanded(
child: Container(
height: double.infinity,
color: Colors.black,
child: Center(
child: GestureDetector(
onTap: () {},
child: Text(
'$intAmount',
style: TextStyle(
color: Colors.amber,
),
),
),
),
),
),
Container(
width: 35,
height: double.infinity,
color: Colors.orange,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.black,
child: GestureDetector(
onTap: () {
setState(() {
intAmount = int.parse(amount);
intAmount++;
amount = intAmount.toString();
print(intAmount);
});
},
child: SizedBox(
child: Image(
image: AssetImage('images/minus.png'),
),
),
),
),
),
)
],
),
)
],
),

结帐Expanded class

关于flutter - 错误使用 ParentDataWidget。 flutter ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63821820/

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