Collapsible

Collapsible Widget

The Collapsible widget allows you to display a list of items in a collapsible or accordion-style UI, where individual sections can be expanded or collapsed. This widget is highly customizable, offering options for styling the headers and bodies, controlling the behavior of sections (whether multiple sections can be open at once), and customizing animations and icons.

Key Properties and Features

  • Accordion Mode: The isAccordion property determines whether only one section can be open at a time (accordion mode) or multiple sections can be open simultaneously. Defaults to true.
  • Section Styling: The headerStyle and bodyStyle properties allow you to customize the appearance of the header and body sections, respectively.
  • Icons: You can add icons to the left and right of each section using leftIcon and rightIcon, and choose whether they flip when the section is opened or closed.
  • Animation: Customize the opening and closing animations of the sections with openAndCloseAnimation and scaleWhenAnimating. Both default to true.
  • Padding and Spacing: Control padding inside sections and spacing between sections using properties like paddingListTop, paddingListBottom, paddingBetweenOpenSections, and paddingBetweenClosedSections. Default values for padding are 0.0.

Properties

PropertyTypeDescription
itemsListA list of items representing the sections of the collapsible. Each item can have its own header, body, and individual styles.
isAccordionbooleanDetermines whether only one section can be open at a time true or multiple sections can be open simultaneously false. Defaults to true.
headerStyleHeaderStyleCompositeDefines the style properties for the section headers.
bodyStyleBodyStyleCompositeDefines the style properties for the section bodies.
leftIconobjectSpecifies an icon to display on the left of the header.
rightIconobjectSpecifies an icon to display on the right of the header.
flipLeftIconIfOpenbooleanDetermines whether the left icon should flip when the section is opened. Defaults to false.
flipRightIconIfOpenbooleanDetermines whether the right icon should flip when the section is opened. Defaults to true.
paddingListTopdoubleSets the padding at the top of the collapsible list. Defaults to 0.0.
paddingListBottomdoubleSets the padding at the bottom of the collapsible list. Defaults to 0.0.
paddingListHorizontaldoubleSets the horizontal padding for the entire list of sections. Defaults to 0.0.
paddingBetweenOpenSectionsdoubleControls the padding between open sections. Defaults to 0.0.
paddingBetweenClosedSectionsdoubleControls the padding between closed sections. Defaults to 0.0.
disableScrollingbooleanIf true, disables scrolling for the collapsible widget. Defaults to false.
openAndCloseAnimationbooleanIf true, enables the open and close animations for sections. Defaults to true.
scaleWhenAnimatingbooleanIf true, the sections will scale when opening and closing as part of the animation. Defaults to true.
accordionIdstringSpecifies a unique identifier for the accordion, useful when dealing with multiple accordions.

Events

EventDescription
onOpenSectionTriggered when a section is opened. You can define actions or code to be executed when a section opens.
onCloseSectionTriggered when a section is closed. Allows you to define actions or code to be executed on section close.

Methods

MethodDescription
openSectionOpens a specific section by its index.
closeSectionCloses a specific section by its index.

Getters

GetterTypeDescription
openSectionsListRetrieves the list of currently open section indices.
headerStyleobjectRetrieves the header style properties of the collapsible.
bodyStyleobjectRetrieves the body style properties of the collapsible.

HeaderStyleComposite

The HeaderStyleComposite is a class that defines the styling options for the headers of each section in the collapsible.

Properties

PropertyTypeDescription
backgroundColorColorThe background color of the header. Defaults to null.
backgroundColorOpenedColorThe background color of the header when the section is opened. Defaults to null.
borderColorColorThe border color of the header. Defaults to null.
borderColorOpenedColorThe border color of the header when the section is opened. Defaults to null.
borderWidthdoubleThe width of the header's border. Defaults to 1.0.
borderRadiusdoubleThe radius of the header's corners. Defaults to 0.0.
paddingEdgeInsetsThe padding inside the header. Defaults to EdgeInsets.zero.

BodyStyleComposite

The BodyStyleComposite is a class that defines the styling options for the body of each section in the collapsible.

Properties

PropertyTypeDescription
backgroundColorColorThe background color of the body. Defaults to null.
borderColorColorThe border color of the body. Defaults to null.
borderWidthdoubleThe width of the body's border. Defaults to 1.0.
borderRadiusdoubleThe radius of the body's corners. Defaults to 0.0.
horizontalPaddingdoubleThe horizontal padding inside the body. Defaults to 0.0.
verticalPaddingdoubleThe vertical padding inside the body. Defaults to 0.0.

Box Styles (Inherited)

This widget also inherits these styles:

PropertyTypeDescription
margininteger/stringMargin with CSS-style notation (1 to 4 integers) e.g. margin: 5 20 5
paddinginteger/stringPadding with CSS-style notation (1 to 4 integers) e.g. padding: 5 20 5
backgroundColorColorThe background color of this widget.
backgroundImageBackgroundImageThe background image of this widget.
backgroundGradientGradientThe background gradient of this widget.
borderBorderThe border of this widget.
shadowShadowThe shadow of this widget
clipContentbooleanSome widgets (such as Image) may bleed through the container when borderRadius is set. Use this to apply a clipping to ensure this does not happen.
widthintegerThe width of this widget.
heightintegerThe height of this widget.
borderRadiusstring or integerThe border radius of the widget. This can be specified using CSS-like notation with 1 to 4 integers. Minimum value: 0.
borderColorinteger or stringSets the border color, starting with '0xFF' for full opacity. Possible values: transparent, black, blue, white, red, grey, teal, amber, pink, purple, yellow, green, brown, cyan, indigo, lime, orange.
borderWidthintegerThickness of the border. Minimum value should be 0.
shadowColorinteger or stringSets the box shadow color starting with '0xFF' for full opacity. Possible values: transparent, black, blue, white, red, grey, teal, amber, pink, purple, yellow, green, brown, cyan, indigo, lime, orange.
shadowOffsetarrayThe values in the array define the horizontal and vertical offset of the shadow. Example: if the shadowOffset is set to [2, 4], the shadow will be offset by 2 pixels horizontally and 4 pixels vertically from its original position.
shadowRadiusstring or integerThe border radius of the widget. This can be specified using CSS-like notation with 1 to 4 integers. Minimum value: 0.
shadowStylestringThe blur style to apply on the shadow: normal, solid, outer, inner.

Base Styles (Inherited)

This widget also inherits these base styles:

PropertyTypeDescription
visiblebooleanToggle a widget visibility on/off. Note that an invisible widget will not occupy UI space, unless the visibilityTransitionDuration is specified.
visibilityTransitionDurationnumberSpecify the duration in seconds when a widget animates between visible and not visible state. Note that setting this value will cause the widget to still occupy the UI space even when it is not visible.
elevationintegerThe z-coordinate at which to place this material relative to its parent. A non-zero value will show a shadow, with its size relative to the elevation value. (Minimum: 0, Maximum: 24)
elevationShadowColorColorThe shadow color for the elevation.
elevationBorderRadiusinteger / stringIf the widget has a borderRadius, this should be changed to have the same value. Use with CSS-like notation (1 to 4 integers).
alignmentAlignmentAlign this widget relative to its parent.
stackPositionTopintegerThe distance of the child's top edge from the top of the stack. This is applicable only for Stack's children.
stackPositionBottomintegerThe distance that the child's bottom edge from the bottom of the stack. This is applicable only for Stack's children.
stackPositionLeftintegerThe distance that the child's left edge from the left of the stack. This is applicable only for Stack's children.
stackPositionRightintegerThe distance that the child's right edge from the right of the stack. This is applicable only for Stack's children.
captureWebPointerbooleanApplicable for Web only. When overlaying widgets on top of certain HTML container (e.g., Maps), the mouse click is captured by the HTML container, causing issue interacting with the widget. Use this to capture and maintain the mouse pointer on your widget.

By utilizing these properties, methods, and events, you can effectively integrate and customize the Collapsible widget to match your application's requirements.