flutter Listview -> 容器 'width' 不工作?

标签 flutter

flutter flutter Listview -> 容器“宽度”不工作?

/示例/ ㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡㅡ

scaffold 
body : ListView
children : [
    Container (
        width: 100, // Not Working 
        height: 100, // Ok
        color: Colors.red.
    ),
]

!!!但是 !!!

scaffold 
body : ListView
children : [
    Stack(
      children : [
        Container (
          width: 100, // OK
          height: 100, // Ok
          color: Colors.red.
        ),
    ]

为什么??

enter image description here

最佳答案

试试下面的代码,把你的 Container 包裹在 UnconstrainedBox()

引用UnconstrainedBox

引用Layout Constraints

ListView(
      shrinkWrap: true,
      children: [
        UnconstrainedBox(
          child: Container(
            width: 100, // OK
            height: 100, // OK
            color: Colors.red,
          ),
        )
      ],
    ),

你的结果-> Image

关于 flutter Listview -> 容器 'width' 不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71509510/

相关文章:

flutter - 列表 map 无法在Dart中使用吗?

listview - SingleChildScrollView里面不可能有ListView吗?

Flutter:在 Stack 中定位 SizedBox 覆盖以显示加载似乎很老套

ios - 无法在 pubspec.yaml 中添加依赖项而不会在 flutter ios 开发中出现错误

iPhone 上的 Flutter 底部填充颜色

image - 在 Flutter 应用程序中添加 360 VR 照片查看器

flutter - 如何在 dart/flutter 中收听流值

ios - Flutter iOS 运行错误 : Could not parse callback cache, 中止恢复

flutter - 如何在Firebase和Bloc中使用json和序列化?错误:将对象转换为可编码对象失败

laravel-5 - 从 laravel API 检索数据到 flutter 应用程序