Accordion

Accordion Widget

The Accordion widget allows you to display a list of items in an 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 limitExpandedToOne property determines whether only one section can be open at a time (accordion mode) or multiple sections can be open simultaneously. Defaults to true.
  • Initial Opening Sequence Delay: The initialOpeningSequenceDelay property allows you to add a delay (in milliseconds) before the initial opening of the sections.
  • 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.
  • Padding and Spacing: Control padding inside sections and spacing between sections using properties like paddingListTop, paddingListBottom, paddingListHorizontal, paddingBetweenOpenSections, and paddingBetweenClosedSections. Default values for padding are 0.0.
  • Animations: Customize the opening and closing animations of the sections with openAndCloseAnimation and scaleWhenAnimating. Both default to true.
  • Scrolling: Disable scrolling for the accordion using the disableScrolling property. Defaults to false.

Properties

PropertyTypeDescription
itemsListA list of items representing the sections of the accordion. Each item can have its own header, body, and individual styles.
limitExpandedToOnebooleanDetermines whether only one section can be open at a time true or multiple sections can be open simultaneously false. Defaults to true.
initialOpeningSequenceDelayint?Specifies a delay (in milliseconds) before the initial opening of the sections. Defaults to null.
headerStyleHeaderStyleCompositeDefines the style properties for the section headers.
bodyStyleBodyStyleCompositeDefines the style properties for the section bodies.
leftIcondynamicSpecifies an icon to display on the left of the header.
rightIcondynamicSpecifies an icon to display on the right of the header.
flipLeftIconIfOpenbool?Determines whether the left icon should flip when the section is opened. Defaults to null.
flipRightIconIfOpenbool?Determines whether the right icon should flip when the section is opened. Defaults to true.
paddingListTopdoubleSets the padding at the top of the accordion list. Defaults to 0.0.
paddingListBottomdoubleSets the padding at the bottom of the accordion list. Defaults to 0.0.
paddingListHorizontaldoubleSets the horizontal padding for the entire list of sections. Defaults to 0.0.
paddingBetweenOpenSectionsdouble?Controls the padding between open sections. Defaults to null.
paddingBetweenClosedSectionsdouble?Controls the padding between closed sections. Defaults to null.
disableScrollingboolIf true, disables scrolling for the accordion widget. Defaults to false.
openAndCloseAnimationbool?If true, enables the open and close animations for sections. Defaults to true.
scaleWhenAnimatingbool?If true, the sections will scale when opening and closing as part of the animation. Defaults to true.

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 accordion.
bodyStyleobjectRetrieves the body style properties of the accordion.

HeaderStyleComposite

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

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.
borderWidthdouble?The width of the header's border. Defaults to null.
borderRadiusdouble?The radius of the header's corners. Defaults to null.
paddingEdgeInsets?The padding inside the header. Defaults to null.

BodyStyleComposite

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

Properties

PropertyTypeDescription
backgroundColorColorThe background color of the body. Defaults to null.
borderColorColorThe border color of the body. Defaults to null.
borderWidthdouble?The width of the body's border. Defaults to null.
borderRadiusdouble?The radius of the body's corners. Defaults to null.
horizontalPaddingdouble?The horizontal padding inside the body. Defaults to null.
verticalPaddingdouble?The vertical padding inside the body. Defaults to null.

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.