Zeba Academy Collapsible
A flexible and reusable Flutter package for building animated collapsible panels, accordions, nested expandable sections, and programmatically controlled expansion interfaces.
zeba_academy_collapsible provides a clean API for creating interactive expandable content with smooth animations, single or multiple expansion modes, nested panels, custom styling, and controller-based state management.
โจ Features
- ๐ฆ Reusable collapsible panels
- ๐ช Accordion support
- ๐ Single-item expansion mode
- ๐ Multiple-item expansion mode
- ๐ณ Nested collapsible panels
- ๐ฌ Smooth expand and collapse animations
- ๐๏ธ Custom animation duration
- ๐ Custom animation curves
- ๐จ Custom header and content styling
- ๐งฉ Custom leading widgets
- ๐ง Custom trailing widgets
- ๐ฎ Programmatic expansion control
- ๐ Expand all items
- ๐ Collapse all items
- ๐ Toggle individual items
- ๐ง External controller support
- ๐ชถ Lightweight and dependency-free
- ๐ฑ Works with Flutter mobile, web, and desktop applications
- ๐ซ No external packages required
๐ฆ Installation
Add the package to your pubspec.yaml:
dependencies:
zeba_academy_collapsible: ^0.0.1
Then run:
flutter pub get
๐ Getting Started
Import the package:
import 'package:zeba_academy_collapsible/zeba_academy_collapsible.dart';
๐ช Basic Accordion
ZebaAccordion(
items: [
CollapsibleItem(
title: const Text('What is Flutter?'),
content: const Text(
'Flutter is a UI toolkit for building beautiful applications.',
),
),
CollapsibleItem(
title: const Text('What is Dart?'),
content: const Text(
'Dart is the programming language used by Flutter.',
),
),
CollapsibleItem(
title: const Text('Is Flutter cross-platform?'),
content: const Text(
'Yes. Flutter supports mobile, web, desktop, and more.',
),
),
],
)
By default, the accordion allows only one item to remain expanded at a time.
๐ Allow Multiple Expanded Items
Set allowMultiple to true:
ZebaAccordion(
allowMultiple: true,
items: [
CollapsibleItem(
title: const Text('Personal Information'),
content: const Text(
'Name, email, and phone number.',
),
),
CollapsibleItem(
title: const Text('Address'),
content: const Text(
'Street, city, and country.',
),
),
CollapsibleItem(
title: const Text('Preferences'),
content: const Text(
'Application preferences.',
),
),
],
)
Users can now expand multiple sections simultaneously.
๐ Initially Expanded Sections
Use initiallyExpanded:
ZebaAccordion(
items: [
CollapsibleItem(
title: const Text('First Section'),
content: const Text(
'This section starts expanded.',
),
initiallyExpanded: true,
),
CollapsibleItem(
title: const Text('Second Section'),
content: const Text(
'This section starts collapsed.',
),
),
],
)
๐งฉ Individual Collapsible Panel
Use ZebaCollapsible when you need a standalone expandable panel:
ZebaCollapsible(
header: const Text('Account Settings'),
child: const Text(
'Your account settings appear here.',
),
)
๐ณ Nested Collapsible Panels
Create nested expandable interfaces:
ZebaCollapsible(
header: const Text('Account Settings'),
child: Column(
children: [
ZebaCollapsible(
header: const Text('Profile'),
child: const Text(
'Profile settings',
),
),
const SizedBox(height: 8),
ZebaCollapsible(
header: const Text('Security'),
child: const Text(
'Security settings',
),
),
],
),
)
You can also combine a collapsible panel with an accordion:
ZebaCollapsible(
header: const Text('Advanced Settings'),
child: ZebaAccordion(
items: [
CollapsibleItem(
title: const Text('Developer Options'),
content: const Text(
'Developer configuration.',
),
),
CollapsibleItem(
title: const Text('Debug Options'),
content: const Text(
'Debug configuration.',
),
),
],
),
)
๐จ Custom Header
Add leading widgets using CollapsibleItem:
ZebaAccordion(
items: [
CollapsibleItem(
leading: const CircleAvatar(
child: Icon(Icons.person),
),
title: const Text(
'Profile',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
content: const Text(
'Your profile information appears here.',
),
),
],
)
๐ง Custom Trailing Widget
You can replace the default expansion icon:
ZebaAccordion(
items: [
CollapsibleItem(
title: const Text('Notifications'),
trailing: const Icon(
Icons.notifications,
),
content: const Text(
'Notification settings.',
),
),
],
)
๐ฌ Custom Animations
Customize the animation duration:
ZebaAccordion(
duration: const Duration(
milliseconds: 500,
),
items: [
CollapsibleItem(
title: const Text('Animated Section'),
content: const Text(
'This section uses a custom animation duration.',
),
),
],
)
Customize the animation curve:
ZebaAccordion(
curve: Curves.easeOutCubic,
items: [
CollapsibleItem(
title: const Text('Smooth Animation'),
content: const Text(
'This section uses a custom animation curve.',
),
),
],
)
๐จ Custom Styling
Customize the accordion appearance:
ZebaAccordion(
backgroundColor: Colors.white,
headerColor: Colors.blueGrey,
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: Colors.grey,
),
items: [
CollapsibleItem(
title: const Text('Styled Section'),
content: const Text(
'Beautiful custom styled content.',
),
),
],
)
๐ฎ Programmatic Control
Create a controller:
final controller = CollapsibleController();
Pass it to the accordion:
ZebaAccordion(
controller: controller,
allowMultiple: true,
items: [
CollapsibleItem(
title: const Text('Section 1'),
content: const Text('Content 1'),
),
CollapsibleItem(
title: const Text('Section 2'),
content: const Text('Content 2'),
),
CollapsibleItem(
title: const Text('Section 3'),
content: const Text('Content 3'),
),
],
)
Expand an Item
controller.expand(0);
Collapse an Item
controller.collapse(0);
Toggle an Item
controller.toggle(0);
Expand Multiple Items
controller.expandAll([0, 1, 2]);
Collapse All Items
controller.collapseAll();
Check Expansion State
final isExpanded = controller.isExpanded(0);
Read Expanded Indexes
final expandedIndexes = controller.expandedIndexes;
๐ API Overview
ZebaCollapsible
A standalone animated collapsible panel.
Main Properties
| Property | Type | Description |
|---|---|---|
header |
Widget |
Header content |
child |
Widget |
Expandable content |
initiallyExpanded |
bool |
Initial expansion state |
duration |
Duration |
Animation duration |
curve |
Curve |
Animation curve |
padding |
EdgeInsetsGeometry |
Content padding |
headerPadding |
EdgeInsetsGeometry |
Header padding |
backgroundColor |
Color? |
Panel background |
headerColor |
Color? |
Header background |
borderRadius |
BorderRadius |
Panel radius |
border |
Border? |
Panel border |
ZebaAccordion
A collection of collapsible items.
Main Properties
| Property | Type | Description |
|---|---|---|
items |
List<CollapsibleItem> |
Accordion items |
allowMultiple |
bool |
Allow multiple open items |
controller |
CollapsibleController? |
External controller |
duration |
Duration |
Animation duration |
curve |
Curve |
Animation curve |
spacing |
double |
Space between items |
onExpansionChanged |
Callback | Expansion state callback |
CollapsibleItem
Represents one accordion item.
CollapsibleItem(
title: const Text('Title'),
content: const Text('Content'),
)
Properties
titlecontentinitiallyExpandedleadingtrailing
CollapsibleController
Controls accordion expansion programmatically.
Methods
expand(int index)
collapse(int index)
toggle(int index)
expandAll(Iterable<int> indexes)
collapseAll()
setExpandedIndexes(Iterable<int> indexes)
isExpanded(int index)
๐งช Testing
Run static analysis:
flutter analyze
Run tests:
flutter test
Run package validation:
flutter pub publish --dry-run
๐ฑ Supported Platforms
| Platform | Supported |
|---|---|
| Android | โ |
| iOS | โ |
| Web | โ |
| Windows | โ |
| macOS | โ |
| Linux | โ |
๐ Project Structure
lib/
โโโ zeba_academy_collapsible.dart
โโโ src/
โโโ controllers/
โ โโโ collapsible_controller.dart
โโโ models/
โ โโโ collapsible_item.dart
โโโ widgets/
โโโ zeba_accordion.dart
โโโ zeba_collapsible.dart
โโโ zeba_collapsible_item.dart
๐ค Contributing
Contributions are welcome and appreciated.
To contribute:
- Fork the repository.
- Create a feature branch.
- Make your changes.
- Add or update tests.
- Run
flutter analyze. - Run
flutter test. - Submit a pull request.
Please ensure that all contributions maintain the existing code quality and package design principles.
๐ Issues and Feature Requests
If you find a bug or have an idea for a new feature, please open an issue in the project repository.
When reporting a bug, please include:
- Flutter version
- Dart version
- Operating system
- Minimal reproduction code
- Expected behavior
- Actual behavior
๐จโ๐ป About Me
โจ Iโm Sufyan bin Uzayr, an open-source developer passionate about building and sharing meaningful projects.
You can learn more about me and my work at:
โก๏ธ sufyanism.com
Or connect with me on:
โก๏ธ LinkedIn
๐ Your All-in-One Learning Hub
๐ Explore courses and resources in coding, technology, and development at Zeba Academy.
Empower yourself with practical skills through curated tutorials, real-world projects, and hands-on experience. Level up your tech game today! ๐ปโจ
Zeba Academy is a learning platform dedicated to coding, technology, and development.
โก๏ธ Visit our main site: zeba.academy
โก๏ธ Explore hands-on courses and resources: code.zeba.academy
โก๏ธ Watch tutorials on YouTube: zeba.academy
โก๏ธ Follow us on Instagram: zeba.academy
๐ License
Copyright ยฉ 2026 Sufyan bin Uzayr
This project is licensed under the GNU General Public License v3.0.
You may use, study, modify, and redistribute this software under the terms of the GPL-3.0 license.
See the LICENSE file for the complete license text.
โญ Support the Project
If you find this package useful:
- โญ Star the repository
- ๐ฆ Publish your own projects using the package
- ๐ Report bugs
- ๐ก Suggest improvements
- ๐ค Contribute to the project
Thank you for visiting! ๐