StreamBuilder
Listview.builder
Card(
child: Container(
width: double.infinity,
padding: EdgeInsets.all(10),
child: Column(
children: [
CardMenuTitle(id: menu.title),
CardMenuImage(menu: menu, index: index),
... ]
...
现在在卡片菜单图像
Widget build(BuildContext context) {
return Stack(
children: [
Container(), //just tried to add empty container to see if it fixes the problem
Positioned(
top: 1, //if I remove this line, it works,
child: Container(
width: double.infinity,
// needed
color: Colors.transparent,
child: Image.asset(
"assets/images/menu/${menu.image}",
fit: BoxFit.cover,
),
),
),
Positioned.fill(
child: Material(
color: Colors.transparent,
child: InkWell(
splashColor: Colors.black.withOpacity(0.5),
onTap: () {
}, // needed
),
),
),
],
);
}}
performLayout((过程中引发了以下断言:BoxConstraints强制使用无限宽度。这些无效约束被提供给_RenderColoredBox的layout((函数由以下人员函数,该函数可能计算了有问题的无效约束:RenderConstraintBox.performLayout(包:flutter/src/rendering/proxy_box.dart:279:14(违规限制包括:BoxConstraints(w=无穷大,0.0<=h<=无穷大(
Positioned(
top: 1, //if I remove this line, it works,
child: Container( //removing container solves the problem but image is not displayed
width: double.infinity,
// needed
color: Colors.transparent,
child: Image.asset(
"assets/images/menu/${menu.image}",
fit: BoxFit.cover,
),
),
),
从位置小部件中删除容器后,错误消失,但不显示图像。
用width: MediaQuery.of(context).size.width
替换width: double.infinity