Tooltip causes infinite height error

How is it possible that I’m getting this error:

The following assertion was thrown during performLayout():
BoxConstraints forces an infinite height.
The offending constraints were:
BoxConstraints(w=1182.0, h=Infinity)

The relevant error-causing widget was:
IconButton

with this code:

SizedBox(
  width: iconsSize,
  height: iconsSize,
  child: IconButton(
    icon: const Icon(Icons.last_page),
    tooltip: 'Last page',
    iconSize: iconsSize,
    padding: const EdgeInsets.all(0),
    onPressed: currentPage < lastPageNum ? lastPage : null,
  ),
),

It happens only when I set the tooltip and I hover over the icon. The same happens if I wrap the SizedBox in the Tooltip Widget.

If it happens also if you wrap the SizedBox it’s probably because of some Widget above this, so we need more context to understand what’s happening

Also what’s is the platform, web?

1 Like

I’m on web.
I can see the exception in the console, but there’s no visual indication of the error; I mean that nothing happens on the screen, the tooltip works, everything around is placed correctly. I’m trying to reproduce the error in a different project, but it’s not easy. Through testing, I noticed that the error doesn’t occur if I simply copy the widget tree without using GoRouter with StatefulShellRoute and StatefulShellBranches.

I had a similar issue, the issue is probably with the StatefulShellRoute.builder. To validate that, try to copy your IconButton directly on the StatefulShellRoute.builder to see if you still have the issue.

For me, the solution was to move the SingleChildScrollView to the child view instead of the ShellRoute.builder.

final router = GoRouter(routes: [
  ShellRoute(
      builder: (context, state, child) =>
          Scaffold(
            body: SingleChildScrollView( // <-- my issue, solved by moving it to the child directly
              child: child
            )
          ),
      routes: [GoRoute(path: "/a", builder: (context, state) => AView())])
]);