---
title: HWSizedBox
description: Give a child a fixed size, or leave a gap.
---
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.page/abausg/home_widget/llms.txt
> Use this file to discover all available pages before exploring further.

# HWSizedBox

Sizes its child to a fixed `width` and/or `height`, exactly like Flutter's `SizedBox`. An axis left `null` is sized by the child, and `double.infinity` takes every pixel the enclosing layout offers. Without a child the box is a gap, and an axis left `null` collapses to zero.

```dart
HWSizedBox.expand(
  child: HWColumn(
    crossAxisAlignment: HWCrossAxisAlignment.start,
    children: [
      HWRow(
        children: [
          HWText.fixed('Left'),
          HWSizedBox(width: 16),
          HWText.fixed('Right'),
        ],
      ),
      HWSizedBox(height: 8),
      HWColoredBox(
        color: HWColor.fixed(0xFF2563EB),
        child: HWSizedBox(
          width: 80,
          height: 40,
          child: HWText.fixed('80 x 40'),
        ),
      ),
      HWBoolConditional(
        data: HWBool('showDetail'),
        whenTrue: HWText.fixed('Detail'),
        whenFalse: HWSizedBox.shrink(),
      ),
    ],
  ),
)
```

## Parameters

| Name     | Type       | Default | Description                                                                |
| -------- | ---------- | ------- | -------------------------------------------------------------------------- |
| `width`  | `double?`  | `null`  | Width in logical pixels, `double.infinity` to fill, `null` to size from the child. |
| `height` | `double?`  | `null`  | Height in logical pixels, `double.infinity` to fill, `null` to size from the child. |
| `child`  | `HWWidget?`| `null`  | Widget being sized. Without one the box is an empty gap.                   |

Two more const constructors, both taking only a `child`:

- `HWSizedBox.shrink({HWWidget? child})` — `width` and `height` of `0`, so the box takes no room. Without a child it renders nothing at all, which is what makes it the hidden branch of an [`HWBoolConditional`](/generator/widgets/hw-conditional) or [`HWDataExists`](/generator/widgets/hw-conditional).
- `HWSizedBox.expand({HWWidget? child})` — `width` and `height` of `double.infinity`, so the box takes every pixel offered. Most useful as the root of a widget, or inside an [`HWColumn`](/generator/widgets/hw-column) / [`HWRow`](/generator/widgets/hw-row) to claim the remaining space.

## Platform mapping

- **iOS:** SwiftUI [`.frame(width:height:alignment:)`](https://developer.apple.com/documentation/swiftui/view/frame(width:height:alignment:)) for the axes with a fixed size and [`.frame(maxWidth:maxHeight:alignment:)`](<https://developer.apple.com/documentation/swiftui/view/frame(minwidth:idealwidth:maxwidth:minheight:idealheight:maxheight:alignment:)>) for the infinite ones. Those are two different overloads, so a box with one fixed and one infinite axis chains two `.frame` modifiers.
- **Android:** Glance [`GlanceModifier.width(...)` / `height(...)`](https://developer.android.com/reference/kotlin/androidx/glance/layout/package-summary) in `dp`, or `fillMaxWidth()` / `fillMaxHeight()` / `fillMaxSize()` for an infinite axis, injected into the child's own composable.
- Inside an `HWColumn` or `HWRow`, an infinite axis running **along** the main axis becomes `defaultWeight()` instead of a fill on Android: a Glance linear layout is a `LinearLayout`, and a child asking to match the parent there would leave its siblings nothing. The stack then takes its whole main axis, as a Flutter `Row` or `Column` does, so the weighted child has room to grow into.
- A child smaller than the box is placed where its **own alignment** puts it, which is what Flutter's tight constraints produce: an [`HWColumn`](/generator/widgets/hw-column) / [`HWRow`](/generator/widgets/hw-row) keeps its `crossAxisAlignment` across the box, an [`HWStack`](/generator/widgets/hw-stack) or [`HWAlign`](/generator/widgets/hw-align) is placed by its own `alignment`, an [`HWImage`](/generator/widgets/hw-image) or [`HWIcon`](/generator/widgets/hw-icon) is centered, and everything else sits at the top start. On iOS that is the `alignment:` of the emitted `.frame`, on Android the natural placement. An [`HWBoolConditional`](/generator/widgets/hw-conditional) / [`HWDataExists`](/generator/widgets/hw-conditional) / [`HWSizeAdaptive`](/generator/widgets/hw-size-adaptive) child whose branches would be placed differently sits at the top start, since iOS applies the one frame around the whole conditional.
- An [`HWImage`](/generator/widgets/hw-image) child **fills** every axis the box sizes and the image leaves open, scaled by its `fit`, also through an `HWPadding`, a colored decoration or a conditional. On iOS the `.frame` resizes the image; on Android the `Image` takes a fill modifier inside the box. An axis the image sizes itself through `width` / `height` keeps that size.
- A box **without a child** is a gap: SwiftUI `Color.clear` in a frame, Glance `Spacer`. Both platforms leave it exactly the size it asks for, so a gap of `HWSizedBox(width: 16)` between two children of an [`HWRow`](/generator/widgets/hw-row) is 16 logical pixels wide and nothing more.
- A box that would render **nothing** renders nothing at all, and a stack gives it neither a gap nor a spacer of its own: `HWSizedBox()` and `HWSizedBox.shrink()` without a child, and any box around a child that renders nothing, such as an [`HWDataOnly`](/generator/widgets/hw-data-only). On Android it is not one of the at most ten children Glance lays out in a `Column` / `Row` either.
- An [`HWColoredBox`](/generator/widgets/hw-colored-box) / [`HWDecoratedBox`](/generator/widgets/hw-decorated-box) child is painted across the whole box, as in Flutter, so it makes no difference whether the `HWSizedBox` goes around the decoration or inside it. An [`HWPadding`](/generator/widgets/hw-padding) between the box and the decoration takes its share first, so the decoration paints the box less the padding. The size also reaches a decoration through each branch of an [`HWBoolConditional`](/generator/widgets/hw-conditional) / [`HWDataExists`](/generator/widgets/hw-conditional) / [`HWSizeAdaptive`](/generator/widgets/hw-size-adaptive) / [`HWAdaptive`](/generator/widgets/hw-adaptive), and through a nested `HWSizedBox` on the axes that box leaves open. On iOS the `.frame` goes inside the `.background` / `.overlay`; on Android a border's `Box` takes the box's size, and its fill and the child fill it.
- The box does **not clip** on iOS, so a child larger than the box overflows; on Android a view always clips to its bounds. Size the child rather than relying on either. There are two exceptions, both clipped on iOS as well: an axis sized to `0`, so the child it hides really is gone, and a child that clips itself, such as an [`HWStack`](/generator/widgets/hw-stack), which the box cuts off at its bounds because Flutter would have sized the stack to the box. A conditional or [`HWSizeAdaptive`](/generator/widgets/hw-size-adaptive) child is clipped to the box as soon as one of its branches clips itself. An infinite axis is no bound, so it adds no clipping.
