Cannot hit test a RenderBox with no size

Cannot hit test a render box with no size.

Quick Answer

A widget with zero size was tapped, typically due to a missing layout constraint.

Why This Happens

In Flutter, a RenderBox with no size (zero width or height) cannot respond to touch events. This happens when a GestureDetector wraps a widget that has no intrinsic size and no constraints to give it one. Provide explicit dimensions or ensure the child has a visible size.

The Problem

GestureDetector(
  onTap: () => print('tapped'),
  child: Container(), // No size!
)

The Fix

GestureDetector(
  onTap: () => print('tapped'),
  child: Container(
    width: 100,
    height: 100,
    color: Colors.blue,
  ),
)

Step-by-Step Fix

  1. 1

    Identify the error

    Look at the error about hitting a render box with no size. A tappable widget has zero dimensions.

  2. 2

    Find the cause

    Check if the GestureDetector's child has no explicit size and is in an unconstrained layout.

  3. 3

    Apply the fix

    Give the child widget explicit width and height, or ensure the parent provides size constraints.

Got the actual stack trace?

Paste it into our free AI explainer to get the cause and the fix for your specific case — no signup, nothing to install.

Explain my error

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free