Zeba Academy Collapsible

pub package pub points likes license

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

  • title
  • content
  • initiallyExpanded
  • leading
  • trailing

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:

  1. Fork the repository.
  2. Create a feature branch.
  3. Make your changes.
  4. Add or update tests.
  5. Run flutter analyze.
  6. Run flutter test.
  7. 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! ๐Ÿ’™