Section(children: Component): Component;
Section(children: Component[]): Component;
Section(props: { header?: Component; footer?: Component }, children: Component[]): Component;
children
Component | Component[]
required
The content of the section.
Configuration options for the section.
A component displayed above the section content. Typically a Text with a headline style.
A component displayed below the section content. Typically a Text with a caption or explanatory note.
Support
Usage
Basic section
Section([
Text("Item 1"),
Text("Item 2"),
Text("Item 3")
])
Section({ header: Text("Settings") }, [
Toggle({ label: "Dark Mode", isOn, setIsOn }),
Toggle({ label: "Notifications", isOn: notifs, setIsOn: setNotifs })
])
Section(
{
header: Text("Account"),
footer: Text("Your email is used for sign-in.")
},
[
Text("user@example.com"),
Text("Change password")
]
)
Inside a List
List([
Section({ header: Text("Fruits") }, [
ForEach(fruits, (fruit) => Text(fruit))
]),
Section({ header: Text("Vegetables") }, [
ForEach(veggies, (veg) => Text(veg))
])
])
Use with LazyVStack and pinnedViews to create sticky section headers:
ScrollView([
LazyVStack({ pinnedViews: "sectionHeaders" }, [
Section({ header: Text("Section A").font("headline") }, [
ForEach(sectionAItems, (item) => Text(item.name))
])
])
])
See Also
- List — scrollable list
- LazyVStack — lazy vertical stack with pinned views