---
title: HWColumn
description: Vertical layout of children.
---
> ## 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.

# HWColumn

Arranges its children vertically. The cross axis is horizontal, the main axis is vertical. Pair with [`HWRow`](/generator/widgets/hw-row) and [`HWSizedBox`](/generator/widgets/hw-sized-box) to build layouts.

```dart
HWSizedBox.expand(
  child: HWColumn(
    mainAxisAlignment: HWMainAxisAlignment.spaceEvenly,
    children: [
      HWText.fixed('Hello World'),
      HWSizedBox.expand(
        child: HWRow(
          mainAxisAlignment: HWMainAxisAlignment.spaceBetween,
          children: [HWText.fixed('1'), HWText.fixed('2')],
        ),
      ),
    ],
  ),
)
```

`mainAxisAlignment` is implemented with `Spacer`s on both platforms, so non-`start` values force children to take only their intrinsic size and stretch the column to the full height available to it.

Children are centred horizontally unless `crossAxisAlignment` says otherwise. [`HWCrossAxisAlignment.baseline`](/generator/styling/hw-alignment) is not one of the values a column accepts — a column's cross axis is horizontal and has no baseline, so asking for it fails generation. Use it on an [`HWRow`](/generator/widgets/hw-row) instead.

## Spacing

`spacing` puts a gap between every two adjacent children, like Flutter's `Column.spacing`: there is none above the first child or below the last. It is in logical pixels, which is points on iOS and dp on Android, and defaults to `0`, so children touch unless you ask for a gap.

```dart
HWColumn(
  spacing: 8,
  children: [
    HWText.fixed('Today'),
    HWText(HWString('agenda')),
  ],
)
```

`mainAxisAlignment` distributes the height left over on top of the gaps:

- `spaceBetween`: every gap is `spacing` plus an equal share.
- `spaceEvenly`: the gaps between children are `spacing` plus a share, the room above the first and below the last child is just the share.
- `start`, `center` and `end`: the children move as one block, gaps included.

The gap stays outside each child, so a child's background or border never covers it. A negative `spacing` fails generation.

## Building from a list

`HWColumn.builder` renders one child per item of a list your app saves, laid out from a single `item` widget:

```dart
HWColumn.builder(
  'events',
  maxItems: 4,
  spacing: 4,
  crossAxisAlignment: HWCrossAxisAlignment.start,
  item: HWText(HWItemData(HWString('title'))),
  whenEmpty: HWText.fixed('No events today'),
)
```

The items are the column's children, so the alignments and `spacing` apply to them as they would to fixed children. `whenEmpty` is the only child while there is no item to render. A builder takes no `children`: to put a header above the items, nest it in another `HWColumn`. See [Lists](/generator/lists) for `HWItemData`, the generated Dart API and the gallery preview.

## Android: at most 10 children

Glance lays out at most 10 children in a `Column`, and every `Spacer` a `mainAxisAlignment` adds counts as one of them. `spacing` counts as nothing, and neither does a child that renders nothing on Android, such as [`HWDataOnly`](/generator/widgets/hw-data-only). A column Android would render with more than 10 fails generation instead of losing children on the home screen. Group some children in a nested `HWColumn`, `HWRow` or [`HWStack`](/generator/widgets/hw-stack), which counts as one child, or use an alignment that adds fewer spacers; [Alignment](/generator/styling/hw-alignment#spacers-and-the-android-child-limit) lists how many each one adds.

A builder's items count the same way. On Android an `HWColumn.builder` therefore needs a `maxItems`, at most 10 with no spacers and fewer with them; see [Android limits](/generator/lists#android-limits).

## Parameters

| Name                  | Type                     | Default      | Description                              |
| --------------------- | ------------------------ | ------------ | ---------------------------------------- |
| `children`            | `List<HWWidget>`         | **required** | Widgets stacked top-to-bottom.           |
| `crossAxisAlignment`  | `HWCrossAxisAlignment?`  | `null` (`center`) | Horizontal alignment of children. `baseline` is rejected. |
| `mainAxisAlignment`   | `HWMainAxisAlignment?`   | `null`       | Vertical distribution of children.       |
| `spacing`             | `double`                 | `0`          | Gap between two adjacent children, in logical pixels. |

`HWColumn.builder` takes these in place of `children`, and `crossAxisAlignment`, `mainAxisAlignment` and `spacing` as above:

| Name         | Type        | Default      | Description                              |
| ------------ | ----------- | ------------ | ---------------------------------------- |
| `list`       | `String`    | **required** (positional) | Key the list is saved under. Also names the generated `saveData` parameter and item class. |
| `item`       | `HWWidget`  | **required** | Rendered once per saved item, in saved order. The only place `HWItemData` reads from. |
| `maxItems`   | `int?`      | `null` (every item) | Renders at most this many items. 1 or more; required for widgets generated for Android. |
| `whenEmpty`  | `HWWidget?` | `null` (empty column) | The column's only child while there is no item to render. |

See [Alignment](/generator/styling/hw-alignment) for the `HWCrossAxisAlignment` and `HWMainAxisAlignment` values.

## Platform mapping

- **iOS:** SwiftUI [`VStack`](https://developer.apple.com/documentation/swiftui/vstack) with `spacing: 0`. The gap is a `.padding(.top, spacing)` on every child but the first. A builder renders its items with a `ForEach` over the saved items, at most `maxItems` of them. A column whose alignment spreads its children takes `.frame(maxHeight: .infinity, alignment: .top)` wherever its spacers might not stretch it: under `spaceBetween` with a single child, and always for a builder.
- **Android:** Glance [`Column`](https://developer.android.com/reference/kotlin/androidx/glance/layout/package-summary#Column(androidx.glance.GlanceModifier,androidx.glance.layout.Alignment.Vertical,androidx.glance.layout.Alignment.Horizontal,kotlin.Function1)). The gap is a top padding on every child but the first, on a `Box` around a child that draws a background or has a fixed size. A child drawn only some of the time — a branch of a conditional, a slot of an `HWSizeAdaptive`, an icon or picture bound to data — takes the gap on whatever it draws, so one drawing nothing leaves no gap. A builder renders its items in a loop over the saved items, at most `maxItems` of them.
