CollapsibleCard class

A card component that can expand and collapse to show additional content.

The CollapsibleCard provides a flexible container that can be expanded to reveal more content. It supports customization of its appearance and behavior through various properties.

CollapsibleCard(
  title: Text('Card Title'),
  subtitle: Text('Optional subtitle'),
  leading: Icon(Icons.star),
  children: [
    ListTile(title: Text('Content item 1')),
    ListTile(title: Text('Content item 2')),
  ],
)

See also:

  • Card, which this component builds upon
  • ExpansionPanel, which provides similar functionality in a different style
Inheritance

Constructors

CollapsibleCard({required Widget title, Key? key, Widget? subtitle, Widget? leading, Widget? trailing, List<Widget>? children, Color? backgroundColor, Color? expandedBackgroundColor, BorderRadius? borderRadius, bool initiallyExpanded = false, ValueChanged<bool>? onExpansionChanged, Duration animationDuration = const Duration(milliseconds: 200), EdgeInsetsGeometry headerPadding = const EdgeInsets.all(16), EdgeInsetsGeometry childrenMargin = EdgeInsets.zero, bool maintainState = false, Widget? divider, String? semanticsLabel, ExpansionControlPosition expansionControlPosition = ExpansionControlPosition.trailing, EmptyChildrenBehavior emptyChildrenBehavior = EmptyChildrenBehavior.disable, bool isDense = false, VoidCallback? onTap, BoxDecoration? childrenDecoration, Widget? childrenDivider})
const

Properties

animationDuration Duration
Duration of the expand/collapse animation.
final
backgroundColor Color?
Background color of the card.
final
borderRadius BorderRadius?
Border radius of the card.
final
children List<Widget>?
The content that appears when the card is expanded.
final
childrenDecoration BoxDecoration?
Decoration for the children container.
final
childrenDivider Widget?
Divider widget between children.
final
childrenMargin EdgeInsetsGeometry
Padding around the expanded content.
final
divider Widget?
Custom divider widget between header and children.
final
emptyChildrenBehavior EmptyChildrenBehavior
Controls whether to hide or disable the expansion control when there are no children.
final
expandedBackgroundColor Color?
Color when the card is expanded.
final
expansionControlPosition ExpansionControlPosition
Controls whether the expansion button appears at the start or end of the header.
final
hashCode int
The hash code for this object.
no setterinherited
headerPadding EdgeInsetsGeometry
Padding around the header content.
final
initiallyExpanded bool
Whether the card is initially expanded.
final
isDense bool
Whether to render the card with dense padding and smaller elements.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
leading Widget?
Leading widget, typically an icon or image.
final
maintainState bool
Whether to maintain the children's state when collapsed.
final
onExpansionChanged ValueChanged<bool>?
Called when the card expands or collapses.
final
onTap VoidCallback?
Called when the header is tapped.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
semanticsLabel String?
Semantics label for accessibility.
final
subtitle Widget?
Optional widget to display below the title.
final
title Widget
The primary content of the card header.
final
trailing Widget?
Optional widget displayed at the end of the card header.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<CollapsibleCard>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited