kipluo
Flutter6 min read3 steps

How to Build an Animated Accordion in Flutter

Flutter's ExpansionTile gives you an accessible expanding row out of the box. When you need a different look, a custom panel is about 50 lines. This guide covers both, plus the semantics and focus details that are easy to miss.

You needFlutter 3.xStatefulWidgetImplicit animations (AnimatedFoo widgets)
Loading demo
The web version of Elastic Accordion. Panels open on a spring; the Flutter ElasticAccordion uses the same values.Component page

1. Start with ExpansionTile

ExpansionTile is a ListTile that expands to show its children. It animates the height, rotates the trailing arrow, and reports expanded or collapsed state to screen readers. For settings screens and FAQs it is often all you need.

faq.dart
ListView(
  children: const [
    ExpansionTile(
      title: Text('Is it a subscription?'),
      children: [
        Padding(
          padding: EdgeInsets.fromLTRB(16, 0, 16, 16),
          child: Text('No. One payment gets every component.'),
        ),
      ],
    ),
    ExpansionTile(
      title: Text('Does it work offline?'),
      children: [
        Padding(
          padding: EdgeInsets.fromLTRB(16, 0, 16, 16),
          child: Text('Yes. Nothing is loaded from the network.'),
        ),
      ],
    ),
  ],
)

2. A custom panel

AnimatedAlign with a heightFactor between 0 and 1, inside a ClipRect, animates a child between collapsed and its natural height without measuring anything. AnimatedRotation turns the arrow.

When collapsed, the body is still in the widget tree. ExcludeFocus and ExcludeSemantics keep its buttons and text out of keyboard focus and screen-reader navigation until the panel is open.

accordion_panel.dart
import 'package:flutter/material.dart';

class AccordionPanel extends StatefulWidget {
  const AccordionPanel({super.key, required this.title, required this.body});

  final String title;
  final Widget body;

  @override
  State<AccordionPanel> createState() => _AccordionPanelState();
}

class _AccordionPanelState extends State<AccordionPanel> {
  bool _open = false;

  @override
  Widget build(BuildContext context) {
    final reduceMotion = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
    final duration = reduceMotion ? Duration.zero : const Duration(milliseconds: 250);

    return Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: [
        Semantics(
          button: true,
          expanded: _open,
          child: InkWell(
            onTap: () => setState(() => _open = !_open),
            child: Padding(
              padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
              child: Row(
                children: [
                  Expanded(child: Text(widget.title, style: Theme.of(context).textTheme.titleMedium)),
                  AnimatedRotation(
                    turns: _open ? 0.5 : 0,
                    duration: duration,
                    child: const Icon(Icons.expand_more),
                  ),
                ],
              ),
            ),
          ),
        ),
        ClipRect(
          child: AnimatedAlign(
            alignment: Alignment.topCenter,
            heightFactor: _open ? 1 : 0,
            duration: duration,
            curve: Curves.easeOutCubic,
            child: ExcludeFocus(
              excluding: !_open,
              child: ExcludeSemantics(
                excluding: !_open,
                child: Padding(
                  padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
                  child: widget.body,
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }
}

3. Kipluo ElasticAccordion

The curve above always takes 250 ms. Kipluo's free ElasticAccordion opens each panel on a spring (stiffness 240, damping 16), so a quick second tap reverses smoothly and the panel settles with a slight stretch. It reports expanded state through Semantics, plays a soft sound on open and close, and supports multiple open panels.

faq_kipluo.dart
import 'package:kipluo/kipluo.dart';

ElasticAccordion(
  multiple: false,
  items: const [
    AccordionItem(title: 'Is it a subscription?', body: Text('No. One payment.')),
    AccordionItem(title: 'Does it work offline?', body: Text('Yes.')),
  ],
)

Accessibility checklist

Tick each one off as you check your build. Your ticks stay in this browser.

0 of 4 checked

Build it yourself or install it

Build it yourself when

ExpansionTile fits your design, or the 50-line custom panel above does.

Install Kipluo when

You want spring-driven panels with sound and Kipluo styles, matching the React Elastic Accordion.

Keep building