【问题标题】:Flutter horizontal ListView BoxConstraints forces an infinite width颤动水平 ListView BoxConstraints 强制无限宽度
【发布时间】:2020-07-09 13:31:57
【问题描述】:

目前我尝试在卡片中显示水平 ListView Builder。 但我总是收到一条错误消息“BoxConstraints 强制使用无限宽度。”

如果我用垂直列表构建一个列表视图,一切正常。 一旦我更改为水平列表,列表就会消失。

我将附上一个屏幕截图,我将在其中标记水平列表视图应位于的区域。 Screnshoot of the current View

这是我对第二张卡片的最后一次尝试: (我删除了第一张卡的代码,所以代码不会太长)

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'),
                  );
                 }),
               )),
              ),
             ),
   ),

【问题讨论】:

  • 对不起,我忘了开头的“你好” :)
  • 首先,删除Expanded 小部件并将width: double.infinity 提供给Container,然后清楚地解释您到底想做什么?
  • @HardikKumar 感谢您的帮助。对不起,如果我的目标不明确。我更新了我的帖子并添加了屏幕截图。希望这会有所帮助:)

标签: flutter dart flutter-layout


【解决方案1】:

我已经更新了您的代码,以便它可以正常运行。

记住,你不能有水平的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')
            );
          }
        ),
      ),
    ),
  ),
),

也许对你有帮助

【讨论】:

  • @HaridkKumar 谢谢!!!我不知道水平列表视图中的列表图块是不允许的。巨大的帮助!谢谢!
猜你喜欢
  • 2019-02-25
  • 2020-09-21
  • 1970-01-01
  • 2020-04-27
  • 1970-01-01
  • 1970-01-01
  • 2021-08-03
  • 1970-01-01
  • 2020-12-22
相关资源
最近更新 更多