Layout & Constraints Questions with Answers

15 practice questions on Layout & Constraints (Flutter & Dart) with answers and step-by-step solutions. Try 10 samples below, then practise all 15 free in the AptiNest app.

Sample questions

Question 1Easy

What is a common way to put a fixed 16-pixel vertical gap between two widgets in a Column?

  1. Spacer(flex: 16)
  2. Gap.vertical(16)
  3. Padding(height: 16)
  4. SizedBox(height: 16)

Answer: D. SizedBox(height: 16)

Explanation

A SizedBox with only a height is an empty box of that size. Spacer takes a share of free space, not a fixed size.

Step-by-step solution

  1. A SizedBox creates a fixed-size empty box.
  2. Setting height: 16 makes it 16 pixels tall.
  3. Placing it in a Column adds a 16-pixel gap.
  4. The final answer is SizedBox(height: 16).

Why the other options are wrong

  • A. Spacer(flex: 16) gives flexible space that grows to fill, not a fixed 16-pixel gap.
  • B. Gap.vertical comes from a third-party package, not core Flutter, so it is not the common built-in way.
  • C. Padding has no height parameter; it takes EdgeInsets, so Padding(height: 16) does not compile.

Tip: Use SizedBox for fixed gaps and Spacer for flexible space.

Question 2Easy

In a Column, what does mainAxisAlignment control?

  1. The order in which the children are painted on screen
  2. How children are placed horizontally across the width
  3. The text alignment inside each Text child of the Column
  4. How children are placed vertically

Answer: D. How children are placed vertically

Explanation

A Column's main axis is vertical, so mainAxisAlignment positions children top to bottom; crossAxisAlignment handles horizontal placement.

Step-by-step solution

  1. MainAxisAlignment controls layout along the main axis of the Column.
  2. Column's main axis is vertical, so mainAxisAlignment places children vertically.
  3. CrossAxisAlignment handles horizontal alignment within the Column.
  4. Option D describes how children are placed vertically.
  5. Final answer: How children are placed vertically.

Why the other options are wrong

  • A. Paint order follows the child list, and mainAxisAlignment does not control it.
  • B. Horizontal placement across the width is crossAxisAlignment in a Column, not mainAxisAlignment.
  • C. Text alignment is set on the Text widget itself, not by a Column's mainAxisAlignment.

Tip: Remember: Column's main axis is vertical, so mainAxisAlignment controls vertical alignment.

Question 3Easy

How do Row and Column arrange their children?

  1. Both stack children on top of each other
  2. Row vertically, Column horizontally
  3. Row horizontally, Column vertically
  4. Both wrap children onto new lines when they run out of space

Answer: C. Row horizontally, Column vertically

Explanation

Row's main axis is horizontal and Column's main axis is vertical. Neither wraps; use Wrap for that.

Step-by-step solution

  1. Row arranges children horizontally.
  2. Column arranges children vertically.
  3. Row's main axis is horizontal, so it places items side by side.
  4. Column's main axis is vertical, so it stacks items top to bottom.
  5. Correct answer: Row horizontally, Column vertically.

Why the other options are wrong

  • A. Column does not stack children on top of each other; it lays them out in a vertical line.
  • B. This swaps the axes: Row goes horizontally and Column vertically, not the other way round.
  • D. Neither wraps onto new lines; that is Wrap's behaviour, while Row and Column stay in one line.

Tip: Remember: Row is horizontal, Column is vertical.

Question 4Easy

Which widget is meant purely for adding empty space around a single child?

  1. Align
  2. Center
  3. Expanded
  4. Padding

Answer: D. Padding

Explanation

Padding insets its child by the given EdgeInsets. Container can also add padding, but Padding is the dedicated, lighter widget.

Step-by-step solution

  1. Padding adds empty space around its single child.
  2. It uses EdgeInsets to control spacing on all sides.
  3. Expanded stretches its child to fill available space.
  4. Center centers its child within itself but doesn't add padding.
  5. Align is used for positioning children in a flexible layout.
  6. Final answer: Padding.

Why the other options are wrong

  • A. Align positions its child within available space; it does not purely add padding around it.
  • B. Center places its child in the middle; it adds no spacing around the child.
  • C. Expanded makes its child fill free space along the flex axis; it does not add empty space.

Tip: Use Padding when you need to add space around a single widget.

Question 5Medium

How does Flexible (with its default fit) differ from Expanded?

  1. There is no difference; Expanded is just the deprecated name for Flexible
  2. Flexible only works in Column, and Expanded only works inside Row
  3. Expanded lets the child be smaller than its share; Flexible forces it to fill
  4. Flexible lets the child be smaller than its share; Expanded forces it to fill

Answer: D. Flexible lets the child be smaller than its share; Expanded forces it to fill

Explanation

Expanded is Flexible with fit: FlexFit.tight. The default Flexible uses FlexFit.loose, so the child may use less than its allotted space.

Step-by-step solution

  1. Flexible has default fit as FlexFit.loose, allowing child to be smaller than share.
  2. Expanded uses FlexFit.tight, forcing child to fill its allocated space.
  3. So Flexible lets child be smaller; Expanded forces it to fill.
  4. This matches option D exactly.
  5. Final answer: Flexible lets the child be smaller than its share; Expanded forces it to fill.

Why the other options are wrong

  • A. Expanded and Flexible differ in fit; Expanded is not just a renamed Flexible.
  • B. Both work in Row and Column alike; neither is restricted to one parent axis.
  • C. The fit is reversed: Expanded uses tight fit to fill, while Flexible uses loose fit.

Tip: Remember: Flexible = loose fit (can shrink), Expanded = tight fit (must fill).

Question 6Medium

What does crossAxisAlignment: CrossAxisAlignment.stretch do in a Column?

  1. Forces each child to fill the Column's full height
  2. Spreads the children evenly from top to bottom
  3. Forces each child to fill the Column's width
  4. Centers every child horizontally inside the Column

Answer: C. Forces each child to fill the Column's width

Explanation

The cross axis of a Column is horizontal; stretch gives children tight width constraints equal to the Column's width.

Step-by-step solution

  1. In a Column, the cross axis runs horizontally.
  2. CrossAxisAlignment.stretch gives children tight constraints on the cross axis.
  3. Tight constraints make each child expand to the Column's maximum width.
  4. Forces each child to fill the Column's width.

Why the other options are wrong

  • A. Stretch acts on the cross axis, which is horizontal in a Column, so height is not stretched.
  • B. Spreading children evenly is a mainAxisAlignment setting, which stretch does not control.
  • D. Centering is crossAxisAlignment.center; stretch makes children fill the width, not center them.

Tip: Use CrossAxisAlignment.stretch to make children fill the Column's width.

Question 7Medium

Which phrase summarises Flutter's layout rule?

  1. Parents copy their size to all children, which then set position
  2. Constraints go down, sizes go up, parents set position
  3. Sizes go down, constraints go up, children set their own position
  4. Every widget measures the screen and then picks its own size

Answer: B. Constraints go down, sizes go up, parents set position

Explanation

A parent passes constraints to each child, the child picks a size within them and reports it back, and the parent decides where to place the child.

Step-by-step solution

  1. Parents pass constraints to children.
  2. Children pick size within constraints and report it.
  3. Parent uses this info to set child's position.
  4. Constraints go down, sizes go up, parents set position.
  5. Final answer: Constraints go down, sizes go up, parents set position.

Why the other options are wrong

  • A. Parents do not copy their size to children; children choose their own size within given constraints.
  • C. The rule goes the other way: constraints flow down and sizes flow up, not sizes down.
  • D. Widgets do not measure the screen to pick their size; the parent's constraints set the limits.

Tip: Remember: constraints flow down, sizes flow up, and positioning is handled by parents.

Question 8Medium

A Row shows yellow-and-black stripes at its right edge in debug mode. What does that mean?

  1. A child widget threw an exception while running its build
  2. Its children are wider than the space available (overflow)
  3. The Row is using an image that has not finished loading yet
  4. The app is running in release mode with warnings enabled

Answer: B. Its children are wider than the space available (overflow)

Explanation

The striped bar is the RenderFlex overflow indicator. Fixes include Expanded or Flexible around a child, smaller content, or Wrap/scrolling.

Step-by-step solution

  1. Yellow-and-black stripes show layout issues in debug mode.
  2. This indicates a child widget is overflowing the Row's space.
  3. Overflow happens when children are wider than available space.
  4. Use Expanded or Flexible to fix layout overflow.
  5. Final answer: Its children are wider than the space available (overflow)

Why the other options are wrong

  • A. An exception would show a red error screen in debug mode, not yellow and black warning stripes.
  • C. Image loading does not produce these stripes; a Row with children too wide does.
  • D. Release mode does not show debug stripes; this overflow marker appears only in debug builds.

Tip: Check for overflow by looking at debug stripes.

Question 9Hard

A Row containing an Expanded child is placed inside a horizontal SingleChildScrollView. What happens?

  1. The Expanded child is quietly converted to a Flexible with loose fit
  2. The Expanded child grows to fill the entire scrollable content area
  3. Layout error: flex children cannot be laid out in an unbounded width
  4. The Row scrolls normally and the Expanded child takes no space at all

Answer: C. Layout error: flex children cannot be laid out in an unbounded width

Explanation

A horizontal scroll view gives its child infinite width, so there is no remaining space to share among flex children. Flutter reports a RenderFlex error.

Step-by-step solution

  1. A horizontal SingleChildScrollView gives its child infinite width.
  2. Row attempts to layout its flex children within that width.
  3. Expanded requires finite remaining space, but the width is unbounded.
  4. Layout error: flex children cannot be laid out in an unbounded width.

Why the other options are wrong

  • A. Expanded is not converted to Flexible; it stays Expanded, and the error comes from the unbounded width.
  • B. Expanded has no finite width to fill inside an unbounded scroll, so it does not grow to the content area.
  • D. The Row does not scroll normally here; the flex layout fails and the app shows an error instead.

Tip: Avoid using Expanded inside a scrollable that provides infinite space.

Question 10Hard

A card should switch between a one-column and a two-column layout depending on how much width its parent gives it, not the screen width. Which widget fits best?

  1. AspectRatio
  2. OrientationBuilder
  3. MediaQuery
  4. LayoutBuilder

Answer: D. LayoutBuilder

Explanation

LayoutBuilder passes the parent's constraints to its builder. MediaQuery reports the whole screen or window size, which can differ from the space the card actually gets.

Step-by-step solution

  1. The card needs its parent's width, not the screen's.
  2. LayoutBuilder gives the parent's constraints.

Why the other options are wrong

  • A. AspectRatio sets a ratio.
  • B. OrientationBuilder reacts to device orientation.
  • C. MediaQuery gives screen size.

Tip: Local size = LayoutBuilder.

Practise all 15 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all Flutter & Dart topics · All topics