Get an error `Failed assertion: line 1687 pos 12: 'hasSize'` when render ListTile inside `Row`

Viewed 38530

I have below code in flutter.

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

But I get this error:

════════ 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?

4 Answers

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

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

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

Add Flexible

Row(
    children: [
      new Flexible(
        child: new TextField(
          decoration: const InputDecoration(helperText: "Enter App ID"),
          style: Theme.of(context).textTheme.body1,
        ),
      ),
    ],
  ),

I was getting exactly this while trying to have a Column with one of its children being a ScopedModelDescendant.

I was going crazy with this same error.

A combination of reading this thread and educating myself on layout widgets gave me the solution:

I've wrapped the ScopedModelDescendant child in a Flexible widget, like this:

Column(
 children: [
  Flexible(child: ScopedModelDescendant<MyAPIProvider>(...)
 ...

And now it works.

Related