Unhandled Exception: Cannot hit test a render box with no size

Solution 1:

For a ListView, set shrinkWrap property to true

shrinkWrap: true

Solution 2:

The problem is that you are placing the GridView inside a Column/Row. The text in the exception gives a good explanation of the error.

To avoid the error you need to provide a size to the GridView inside.

I propose you this code that uses an Expanded to inform the horizontal size (maximum available) and the SizedBox (Could be a Container) for the height:

Column(
  children: <Widget>[
    Expanded(
      child: SizedBox(
          height: 200.0,
          child: RecentlyViewed()
      ),
    ),
    new IconButton(
      icon: Icon(Icons.remove_circle),
      onPressed: () {},
    ),
  ],
);

Solution 3:

I had the same error & in my case, The reason was SingleChildScrollView()

I add the ListView.builder into the container and set the container height as height:MediaQuery.of(context).size.height, and it worked for me.

Here is the sample :

class ListWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      height:MediaQuery.of(context).size.height,
      child: ListView.builder(
        itemCount: 5,
        itemBuilder: (context, index) {
          return ListTile(
            title: Text('Contact $index'),
          );
        },
      ),
    );
  }
}

Now Add the ListWidget in SingleChildScrollView()

return SingleChildScrollView(
        child: Column(
          children: [
            //.......
            ListWidget(),
          ],
        )
    );

You can use it like this or you can simply add it in the SingleChildScrollView in case if you don't want to add anything rather than a list.