当在`Row`中渲染ListTile时,得到一个错误的'Failed assertion:line 1687 pos 12:'hasSize'`。

我下面的代码扑朔迷离。

Widget build(BuildContext context) {
    return Center(
      child: Card(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Row(
              children: <Widget>[
                SizedBox(
                    height: 100,
                    child: ListTile(
                      leading: IconButton(
                        iconSize: 30,
                        icon: roundImage(post.userPicture, Icon(Icons.person)),
                        onPressed: () {},
                      ),
                      subtitle: Text(this.post.message),
                    )),
              ],
            ),
          ],
        ),
      ),
    );
  }

但是我得到这个错误:

════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderPhysicalShape#7713c relayoutBoundary=up3
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1687 pos 12: 'hasSize'
The relevant error-causing widget was
    Card 

I have added SizedBox in the Row but it still complains about hasSize error. How can I solve this issue?

评论
韦小宝
韦小宝

It not clear what you try to achieve, but instead of using SizedBox you can try wrapping inside Expanded or Flexible widgets.

点赞
评论
jquia
jquia

Based on this: https://github.com/hanshengchiu/reorderables/pull/60

I tried adding a width of 200 to your SizedBox and it worked.

Although using Expanded as suggested by @dhanasekar works well too.

点赞
评论