expandable 3.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 98

Expandable #

A Flutter widget that can be expanded or collapsed by the user.

Introduction #

This library helps implement expandable behavior as prescribed by Material Design:

animated image

Expandable should not be confused with ExpansionPanel. ExpansionPanel, which is a part of Flutter material library, is designed to work only within ExpansionPanelList and cannot be used for making other widgets, for example, expandable Card widgets.

Usage #

The easiest way to make an expandable widget is to use ExpandablePanel:

class ArticleWidget extends StatelessWidget {
  final Article article;

  Widget build(BuildContext context) {
    return ExpandablePanel(
      header: Text(article.title),
      collapsed: Text(article.body, softWrap: true, maxLines: 2, overflow: TextOverflow.ellipsis,),
      expanded: Text(article.body, softWrap: true, ),
      tapHeaderToExpand: true,
      hasIcon: true,

ExpandablePanel has a number of properties to customize its behavior, but it's restricted by having a title at the top and an expand icon shown as a down arrow (on the right or on the left). If that's not enough, you can implement custom expandable widgets by using a combination of Expandable, ExpandableNotifier, and ExpandableButton:

class EventPhotos extends StatelessWidget {

  Widget build(BuildContext context) {
    return ExpandableNotifier(  // <-- Provides ExpandableController to its children
      child: Column(
        children: [
          Expandable(           // <-- Driven by ExpandableController from ExpandableNotifier
            collapsed: ExpandableButton(  // <-- Expands when tapped on the cover photo
              child: buildCoverPhoto(),
            expanded: Column(  
              children: [
                ExpandableButton(       // <-- Collapses when tapped on
                  child: Text("Back"),

Automatic Scrolling #

Expandable widgets are often used within a scroll view. When the user expands a widget, be it an ExpandablePanel or an Expandable with a custom control, they expect the expanded widget to fit within the viewable area (if possible). For example, if you show a list of articles with a summary of each article, and the user expands an article to read it, they expect the expanded article to occupy as much screen space as possible. The Expandable package contains a widget to help implement this behavior, ScrollOnExpand. Here's how to use it:

   ExpandableNotifier(      // <-- This is where your controller lives
     ScrollOnExpand(        // <-- Wraps the widget to scroll
        ExpandablePanel(    // <-- Your Expandable or ExpandablePanel

Why a separate widget, you might ask? Because generally you might want to to show not just the expanded widget but its container, for example a Card that contains it. See the example app for more details on the usage of ScrollOnExpand.

Migration #

If you have migration issues from a previous version, read the Migration Guide.


  • Added iconColor property to ExpandablePanel

[3.0.0+1] - 06/14/2019

  • Updated README and example app.

[3.0.0] - 06/13/2019

  • Added ShowOnExpand widget.
  • Moved initialExpanded from ExpandablePanel to ExpandableNotifier.
  • Moved animationDuration from Expandable to ExpandableController.
  • Made ExpandableNotifier to be a stateful widget.
  • Made ExpandablePanel a stateless widget.

[2.2.3] - 06/13/2019

  • Added the optional crossFadePoint parameter.

[2.2.2] - 06/09/2019

  • Disabled the iconColor parameter until version 1.7.3 is published to stable.

[2.2.1] - 06/09/2019

  • Added the optional iconColor parameter to ExpandablePanel.

[2.2.0] - 06/06/2019

  • Added the optional headerAlignment parameter to ExpandablePanel.

[2.1.1] - 04/17/2019

  • Added the optional key parameter to Expandable and ExpandablePanel.

[2.1.0] - 04/5/2019

  • ExpandablePanel does not lose its state if its parent is rebuilt.
  • Example file is moved to example folder for ease of running it.

[2.0.0] - 02/14/2019

  • Eliminated the dependency on ScopedModel.
  • Introduced ExpandableNotifier and ExpandableController.
  • This is a breaking change. See README.md for details on migration from 1.x to 2.0.

[1.1.0] - 02/01/2019

  • Added ExpandablePanel, a configurable expandable widget with optional header and icon.

[1.0.0] - 01/29/2019

  • Initial release.


example #

A new Flutter project.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  expandable: ^3.0.1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:expandable/expandable.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Oct 21, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4


Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/expandable.dart.

Run flutter format to format lib/expandable.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0-dev.0.5.flutter-a1668566e5 < 3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies