Anyne知道此错误是什么吗?我认为有些孩子不能放在东西里?
接收到不兼容父数据的RenderObject的所有权链为: _GestureSemantics←RawGestureDetector←GestureDetector←扩展←彩色框←容器←填充←彩色框←ConstrainedBox←容器←⋯
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'),
),
),
),
),
),
),
)
],
),
)
答案 0 :(得分:0)
我已经更新了您的代码,问题是您不能在子级中使用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'),
),
),
),
),
),
)
],
),
)
],
),