Collapsible constructor

const Collapsible({
  1. Key? key,
  2. required List<Widget> children,
  3. bool? isExpanded,
  4. ValueChanged<bool>? onExpansionChanged,
})

Creates a Collapsible widget with the specified children.

Parameters:

  • children (List
  • isExpanded (bool?, optional): Initial expansion state for uncontrolled mode.
  • onExpansionChanged (ValueChanged

Mode Selection

  • Uncontrolled Mode: When onExpansionChanged is null, the widget manages its own state using isExpanded as the initial value.
  • Controlled Mode: When onExpansionChanged is provided, the parent must manage state and update isExpanded accordingly.

Example (Uncontrolled):

Collapsible(
  isExpanded: true,
  children: [
    CollapsibleTrigger(child: Text('Toggle Me')),
    CollapsibleContent(child: Text('Hidden content')),
  ],
);

Example (Controlled):

bool _expanded = false;

Collapsible(
  isExpanded: _expanded,
  onExpansionChanged: (expanded) => setState(() => _expanded = !_expanded),
  children: [
    CollapsibleTrigger(child: Text('Toggle Me')),
    CollapsibleContent(child: Text('Hidden content')),
  ],
);

For more information, visit: https://sunarya-thito.github.io/shadcn_flutter/#/components/collapsible

Implementation

const Collapsible({
  super.key,
  required this.children,
  this.isExpanded,
  this.onExpansionChanged,
});