CupertinoListSection constructor Null safety

const CupertinoListSection(
  1. {Key? key,
  2. List<Widget>? children,
  3. Widget? header,
  4. Widget? footer,
  5. EdgeInsetsGeometry margin = _kDefaultRowsMargin,
  6. Color backgroundColor = CupertinoColors.systemGroupedBackground,
  7. BoxDecoration? decoration,
  8. Clip clipBehavior = Clip.none,
  9. double dividerMargin = _kBaseDividerMargin,
  10. double? additionalDividerMargin,
  11. double? topMargin = _kMarginTop,
  12. bool hasLeading = true}
)

Creates a section that mimics standard iOS forms.

The base constructor for CupertinoListSection constructs an edge-to-edge style section which includes an iOS-style header, the dividers between rows, and borders on top and bottom of the rows. An example of such list section are sections in iOS Settings app.

The header parameter sets the form section header. The section header lies above the children rows, with margins that match the iOS style.

The footer parameter sets the form section footer. The section footer lies below the children rows.

The children parameter is required and sets the list of rows shown in the section. The children parameter takes a list, as opposed to a more efficient builder function that lazy builds, because forms are intended to be short in row count. It is recommended that only CupertinoFormRow and CupertinoTextFormFieldRow widgets be included in the children list in order to retain the iOS look.

The margin parameter sets the spacing around the content area of the section encapsulating children, and defaults to zero padding.

The decoration parameter sets the decoration around children. If null, defaults to CupertinoColors.secondarySystemGroupedBackground. If null, defaults to 10.0 circular radius when constructing with CupertinoListSection.insetGrouped. Defaults to zero radius for the standard CupertinoListSection constructor.

The backgroundColor parameter sets the background color behind the section. If null, defaults to CupertinoColors.systemGroupedBackground.

The dividerMargin parameter sets the starting offset of the divider between rows.

The additionalDividerMargin parameter adds additional margin to existing dividerMargin when hasLeading is set to true. By default, it offsets for the width of leading and space between leading and title of CupertinoListTile, but it can be overwritten for custom look.

The hasLeading parameter specifies whether children CupertinoListTile widgets contain leading or not. Used for calculating correct starting margin for the divider between rows.

The topMargin is used to specify the margin above the list section. It matches the iOS look by default.

The content will be clipped (or not) according to this option.

See the enum Clip for details of all possible options and their common use cases.

Implementation

const CupertinoListSection({
  super.key,
  this.children,
  this.header,
  this.footer,
  this.margin = _kDefaultRowsMargin,
  this.backgroundColor = CupertinoColors.systemGroupedBackground,
  this.decoration,
  this.clipBehavior = Clip.none,
  this.dividerMargin = _kBaseDividerMargin,
  double? additionalDividerMargin,
  this.topMargin = _kMarginTop,
  bool hasLeading = true,
}) : assert((children != null && children.length > 0) || header != null),
     type = CupertinoListSectionType.base,
     additionalDividerMargin = additionalDividerMargin ??
         (hasLeading ? _kBaseAdditionalDividerMargin : 0.0);