Skip to content
tezvyn:
Menu

Explain 'constraints go down, sizes go up, parent sets position.'

Source: docs.flutter.devMediumHow cards are made

Tests Flutter layout protocol and unbounded width errors. Strong answers trace how a child gets infinite width from a scrolling parent and fix it with a bounded wrapper. Red flag: blaming the child without tracing parent constraints.

What's really being asked

Whether you understand Flutter's layout algorithm as a negotiation between parent and child rather than a single top-down assignment. Senior engineers need to debug overflow errors without guessing, and that requires knowing how constraints and sizes flow in opposite directions.

The full answer

First, a crisp statement of the rule: constraints travel down the tree from parent to child, the child replies with its own size up to the parent, and only then does the parent decide the child's position. Second, the distinction between tight constraints, loose constraints, and unbounded constraints. Third, a concrete error scenario where a scrolling widget like ListView passes an unbounded constraint to its child, and how that triggers a layout failure. Fourth, the fix: wrapping the offending child in Expanded or Flexible when inside a Row or Column, or using a bounded parent like SizedBox to stop infinite constraints from propagating.

The mistakes people make

Saying Flutter layout is just like the web or that widgets choose their own positions. Blaming the child widget that throws the error instead of tracing which parent passed an infinite constraint. Recommending a Wrap widget or random shrinkWrap without explaining why the constraint direction matters. Claiming that setting width double infinity always fixes unbounded errors, when it actually causes them in unbounded parents.

What usually comes next

How does BoxConstraints work under the hood? What is the difference between tight and loose constraints? Why does a Row inside a vertical ListView sometimes fail while a Column does not? How would you implement a custom RenderBox that respects this protocol? When is it safe for a parent to pass unbounded constraints?

A concrete example

A horizontal ListView contains a Column. Because the ListView scrolls horizontally, it passes its child an unbounded width constraint. Inside that Column is a Container with width set to double infinity. During layout, the Container asks for infinite width, but the Column cannot satisfy that because its own width constraint is unbounded. Flutter throws an unbounded width error. To diagnose, you trace upward: the error is not the Container's fault, but the horizontal ListView's removal of the width bound. The fix is to wrap the Column in a SizedBox with a fixed width so the Column receives a tight width constraint, which it can then pass down to the Container. Alternatively, replace double infinity with a fixed width or use a flex parent that bounds the child properly.

Interview question

A horizontal ListView holds a Column containing a Container with width: double.infinity, causing an unbounded width error. What is the fundamental reason this fails?

  • a.The ListView passes an unbounded width constraint downward, so the Column cannot offer a finite width to the Container.Correct
  • b.The Container wrongly asks for infinite width without verifying its parent's available space.
  • c.Flutter computes widget positions before sizes during layout, preventing the Container from resolving its width.
  • d.Wrapping the Column in Expanded would force the ListView to supply a bounded width to the Column.
Why?

Constraints flow from parent to child, so the ListView's unbounded width prevents the Column from giving the Container a finite width; blaming the Container is wrong because the child merely responds to the constraint it receives.

Just read this? Test yourself on what you have been reading.

Read the original → docs.flutter.dev

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on flutter — each one lists the topics its interview covers.

See open roles