fha*_*s21 1 dart flutter flutter-layout
目前我尝试在卡片中显示水平 ListView Builder。但我总是收到一条错误消息“ BoxConstraints 强制无限宽度”。
如果我构建一个带有垂直列表的列表视图,一切都会正常。一旦我更改为水平列表,该列表就会消失。
我将附上一个屏幕截图,其中标记了水平列表视图应位于的区域。 当前视图的截图
这是我对第二张卡的最后一次尝试:(我删除了第一张卡的代码,因此代码不会太长)
Expanded(
child: Container(
height: 250.0,
child: Card(
color: Color(_colors.getBackgroundColor()),
elevation: 10.0,
shadowColor: Colors.black54,
margin: EdgeInsets.all(8.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
side: BorderSide(
color: Color(_colors.getLightMainColor()))),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 250.0,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 1,
itemBuilder: (context, index) {
return ListTile(
title: Text('Test'),
);
}),
)),
),
),
),
Run Code Online (Sandbox Code Playgroud)
我已经更新了您的代码,以便它可以正常运行。
请记住,你不能水平ListTile
如果您想要其他东西,请告诉我
Container(
height: 250.0,
width: double.infinity,
child: Card(
color: Colors.red,
elevation: 10.0,
shadowColor: Colors.black54,
margin: EdgeInsets.all(8.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
side: BorderSide(
color: Colors.blue,
),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 250.0,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 5,
itemBuilder: (context, index) {
return Container(
width: 250.0,
child: Text('Test')
);
}
),
),
),
),
),
Run Code Online (Sandbox Code Playgroud)
它可能对你有帮助
| 归档时间: |
|
| 查看次数: |
1612 次 |
| 最近记录: |