Skip to main content

🧩 Section Widget

Section is a reusable layout widget that displays a styled content block with a header, body, and an optional call-to-action area (typically a row of buttons).
It supports different visual styles (primary, secondary, success, danger) and configurable outer margin spacing (simple, double).


🧱 Constructor

Section({
required Widget header,
required Widget body,
Widget? callToAction,
String? style,
SectionMargin sectionMargin = SectionMargin.simple,
})

📐 Parameters

ParameterTypeRequiredDefaultDescription
headerWidgetTop widget of the section (usually a title or heading).
bodyWidgetMain content of the section.
callToActionWidget?nullBottom widget, usually a row of action buttons. Must be an instance of [ActionWidget] — this is enforced by the type system at compile time.
styleString?nullVisual background style (primary, secondary, success, danger).
sectionMarginSectionMarginSectionMargin.simpleControls the outer spacing (simple or double).

🎨 Supported Styles

StyleBackground color
primaryColors.blue.shade50
secondaryColors.grey.shade200
successColors.green.shade50
dangerColors.red.shade50
nullNo background

📏 Margin Options

enum SectionMargin {
simple, // EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0)
double // EdgeInsets.symmetric(horizontal: 32.0, vertical: 16.0)
}

Used to control the space between the Section and surrounding widgets.


💡 Example Usage

Section(
style: 'primary',
sectionMargin: SectionMargin.double,
header: Text("Ready to continue?"),
body: Text("Click one of the buttons below to proceed."),
callToAction: ActionWidget(
alignment: ActionAlignment.right,
buttons: [
Button(label: "Cancel", onPressed: () {}),
Button(label: "Confirm", onPressed: () {}, fill: true),
],
),
)

📌 Notes

  • callToAction must be an instance of ActionWidget — if you pass a different widget, the compiler will throw an error.
  • ActionWidget can hold up to 3 buttons, with a maximum of 2 containing text.
  • The Section automatically applies padding and border radius when a background style is set.
  • Future improvements: apply breakpoints and MediaQuery to propagate style to header.
  • Colors in getBackgroundColor will be replaced with tokens from mix_tokens.dart in the future.