Skip to content

Spec: HStack

Matt Carroll edited this page Mar 11, 2024 · 2 revisions

"A view that arranges its subviews in a horizontal line."

https://developer.apple.com/documentation/swiftui/hstack/

Layout

TODO:

Typography

TODO:

Accessibility

TODO:

Localization

TODO:

Technical Design

/// A layout widget that displays its children horizontally, like a row.
///
/// An `HStack` tightly wraps its [children]. Each child must have an intrinsic width
/// to be visible in an `HStack`.
class HStack extends StatelessWidget {
    const HStack(this.children, {
      this.alignment = VerticalAlignment.center,
      this.spacing,
    });

    /// The vertical (cross-axis) alignment of the [children] within this [HStack].
    ///
    /// See [VerticalAlignment] for more info about the available alignments.
    final VerticalAlignment alignment;
    
    /// The horizontal spacing between each of the [children] in this [HStack].
    final double? spacing;
    
    /// Child widgets, which are displayed horizontally in a row-style layout.
    final List<Widget> children;
}

enum VerticalAlignment {
    /// Alignment with the top of a bounding space.
    top,
    
    /// Alignment that's equidistant from the top and bottom of a bounding space.
    center,
    
    /// Alignment with the bottom of a bounding space.
    bottom,
    
    /// Alignment with the baseline of the first line of text within another widget.
    firstTextBaseline,
    
    /// Alignment with the baseline of the last line of text within another widget.
    lastTextBaseline,
}