확장 가능한 패키지는 일반적으로 헤더 또는 아이콘으로 트리거되는 콘텐츠를 확장 및 축소 상태 간에 전환할 수 있는 Flutter 위젯을 제공합니다. 사용자가 필요에 따라 자세한 정보를 표시하거나 숨길 수 있도록 하여 사용자 인터페이스의 상호작용을 향상시키고 공간 효율성과 탐색을 개선합니다. 목록, 자주 묻는 질문(FAQ), 설정 섹션에 적합하며 부드러운 애니메이션과 사용자 정의 가능한 헤더를 지원합니다. 이 패키지는 Android, iOS, 웹, macOS, Windows, Linux 등 모든 주요 플랫폼에서 호환됩니다.
사용 사례
자주 묻는 질문 섹션
접을 수 있는 목록
설정 패널
동적 콘텐츠 숨기기
사용자 프로필 세부 정보
인터랙티브 폼
주요 기능
부드러운 전개/접기 애니메이션
사용자 정의 가능한 헤더 및 아이콘
여러 확장 상태를 지원합니다
기존 위젯과의 간편한 통합
크로스 플랫폼 호환성
사용자 정의 지속 시간 및 곡선
적합한 대상
인터랙티브 UI를 구축하는 개발자
밀집된 콘텐츠 레이아웃을 가진 앱
접을 수 있는 섹션이 필요한 모바일 및 웹 애플리케이션
재사용 가능한 컴포넌트를 찾는 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:
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:
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:
classEventPhotosextendsStatelessWidget{
@overrideWidgetbuild(BuildContext context) {
returnExpandableNotifier( // <-- 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 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.