fossui
Components

Accordion

A vertical stack of headers that expand to reveal content, one or many at a time.

An accordion stacks disclosure panels. Each item has a header and a body; tapping the header expands or collapses its panel with an animated height. It follows the disclosure pattern and is fully operable from the keyboard, with arrow keys moving between headers and Home and End jumping to the ends.

Accordion
import 'package:fossui/fossui.dart';

FossAccordion(
  children: [
    FossAccordionItem(
      value: 'shipping',
      title: Text('Shipping'),
      child: Text('Ships within two business days.'),
    ),
    FossAccordionItem(
      value: 'returns',
      title: Text('Returns'),
      child: Text('Free returns within 30 days.'),
    ),
  ],
);

Each item carries a stable value, which identifies it in the open set.

Single or multiple

By default only one panel stays open at a time, and opening another closes the last. Set multiple to let panels open independently.

FossAccordion(
  multiple: true,
  children: items,
);

Collapsible

In single mode, collapsible is true by default, so the open panel can be closed by tapping its header. Set it to false to keep exactly one panel open at all times.

FossAccordion(
  collapsible: false,
  initialValue: const {'shipping'},
  children: items,
);

Controlled and uncontrolled

Pass initialValue for an uncontrolled accordion that tracks its own open set. For a controlled accordion, pass value and update it from onValueChanged.

FossAccordion(
  value: _open,
  onValueChanged: (open) => setState(() => _open = open),
  children: items,
);

Disabled items

Set enabled: false on an item to make its header inert. The rest of the accordion stays interactive.

FossAccordionItem(
  value: 'archived',
  title: Text('Archived'),
  enabled: false,
  child: Text('Unavailable.'),
);

One-off styling

Global retheming is the first choice, but a single accordion can override its resolved text, chevron, dividers, and padding with a FossAccordionStyle. Every field is optional and falls back to the theme.

FossAccordion(
  style: const FossAccordionStyle(
    dividerColor: Color(0x11000000),
  ),
  children: items,
);

API

FossAccordion

PropTypeDefaultDescription
childrenList<FossAccordionItem>requiredThe stacked items, in order.
multipleboolfalseWhether more than one panel can stay open.
collapsiblebooltrueIn single mode, whether the open panel can be closed.
initialValueSet<String>?nullOpen set for an uncontrolled accordion.
valueSet<String>?nullOpen set for a controlled accordion.
onValueChangedValueChanged<Set<String>>?nullFires with the next open set.
styleFossAccordionStyle?nullPer-instance overrides on the theme.

FossAccordionItem

PropTypeDefaultDescription
valueStringrequiredStable identity of the item in the open set.
titleWidgetrequiredHeader content.
childWidgetrequiredPanel content, revealed when open.
enabledbooltrueWhether the header responds to input.

FossAccordionStyle

FieldTypeDefaultDescription
titleTextStyleTextStyle?nullText style of the header title.
panelTextStyleTextStyle?nullText style of the panel content.
chevronColorColor?nullColor of the header chevron.
dividerColorColor?nullColor of the hairline under each item.
headerPaddingEdgeInsetsGeometry?nullPadding around the header row.
panelPaddingEdgeInsetsGeometry?nullPadding around the panel content.

Live demo

Open the interactive gallery to try single and multiple modes with live knobs.

On this page