パッケージ、リポジトリ、アプリカテゴリを検索

expandable のカバー
パッケージ詳細v5.0.1

expandable

ヘッダーまたはアイコンをクリックすることで展開または折りたたみ可能なFlutterウィジェットです。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
30.8万
いいね数
1830
Pub ポイント
140

パッケージをインストール

flutter pub add expandable

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

拡張可能なパッケージは、通常ヘッダーまたはアイコンによってトリガーされる、コンテンツを展開状態と折りたたみ状態の間で切り替えられるFlutterウィジェットを提供します。ユーザーインターフェースのインタラクティビティを向上させ、ユーザーが必要に応じて詳細情報を表示または非表示にすることができ、スペース効率とナビゲーションを改善します。リスト、よくある質問、設定セクションに適しており、スムーズなアニメーションとカスタマイズ可能なヘッダーをサポートしています。このパッケージは、Android、iOS、Web、macOS、Windows、Linuxを含むすべての主要プラットフォームで互換性があります。

用途

  • よくある質問セクション
  • 折りたたみ可能なリスト
  • 設定パネル
  • 動的コンテンツの非表示
  • ユーザーのプロフィール詳細
  • インタラクティブフォーム

主な機能

  • スムーズな展開/折りたたみアニメーション
  • カスタマイズ可能なヘッダーとアイコン
  • 複数の展開状態をサポートしています
  • 既存のウィジェットとの簡単な統合
  • クロスプラットフォーム互換性
  • カスタマイズ可能な期間とカーブ

適している対象

  • インタラクティブなUIを構築する開発者
  • 濃密なコンテンツレイアウトを持つアプリ
  • 折りたたみ可能なセクションを必要とするモバイルおよびWebアプリケーション
  • 再利用可能なコンポーネントを探しているUIデザイナー
  • 応答性のあるコンテンツ管理を必要とするプロジェクト

注意事項

  • 大規模なデータセットではパフォーマンスに影響を与える可能性があります
  • 慎重な状態管理が必要です
  • ユーザー体験のため、アニメーションタイミングの調整が必要になる場合があります
  • 追加の論理なしで単一レベルの展開に限定
  • カスタマイズなしでは複雑なネスト構造には適していない

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

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;
  
  ArticleWidget(this.article);

  @override
  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 {

  @override
  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: [
                buildAllPhotos(),
                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 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.

Themes

Version 4.0 introduced themes to expandable widgets. Themes greatly simplify visual customization and as well as future extensibility. Each expandable widget can get its theme data directly via the constructor or from the nearest ExpandableTheme widget:

  ExpandableTheme(
    data: ExpandableThemeData(
        iconColor: Colors.red, 
        animationDuration: const Duration(milliseconds: 500)
    ),
      // ...
      Expandable(  // 500 milliseconds animation duration
      ),

      // ...
      ExpandablePanel(  // <-- Blue icon color, 500 milliseconds animation duration
        theme: ExpandableThemeData(iconColor: Colors.blue),
  
      ),
  )

ExpandableTheme widgets can be nested, in which case inner definitions override outer definitions. There is a default theme with fallback values defined in ExpandableThemeData.defaults.

Prior to version 4.0, theme parameters were passed to widget constructors directly. These parameters are now deprecated and will be removed in the next release.

Icon Customization

There are several theme properties that help customize the expand/collapse icon:

  • hasIcon - should the icon be shown in the header of [ExpandablePanel];
  • iconSize - icon size;
  • iconColor - icon color;
  • iconPadding - icon padding;
  • iconPlacement - icon placement in the header;
  • iconRotationAngle - the angle to which to rotate the icon;
  • expandIcon - icon face to use in the collapsed state;
  • collapseIcon - icon face to use in the expanded state.

When specifying a custom icon, you have the option to use the same icon for expand/collapse or to use two different icons. If using the same icon, specify the same value for expandIcon and collapseIcon, and that icon will be shown as-is in the collapsed state and upside-down in the expanded state.

Migration

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

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト