Collapsible constructor
const
Collapsible({})
Creates a Collapsible widget with the specified children.
Parameters:
children(ListisExpanded(bool?, optional): Initial expansion state for uncontrolled mode.onExpansionChanged(ValueChanged
Mode Selection
- Uncontrolled Mode: When
onExpansionChangedis null, the widget manages its own state usingisExpandedas the initial value. - Controlled Mode: When
onExpansionChangedis provided, the parent must manage state and updateisExpandedaccordingly.
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,
});