搜索插件、代码仓与 APP 分类

expandable_page_view 封面
插件详情v1.3.0

expandable_page_view

一个 PageView 小部件,其高度会根据当前显示的页面进行调整

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
17.3万
喜欢数
596
Pub 分数
160

安装插件

flutter pub add expandable_page_view

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

expandable_page_view 包通过根据当前可见页面的内容动态调整其高度,增强了 Flutter 的 PageView。这使得每个页面可以具有不同的高度,同时保持整体布局的流畅和响应式滚动。适用于表单、卡片或动态列表等可变高度内容的应用程序。该包支持所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,确保在各种设备上行为一致。

适合场景

  • 动态表单页面
  • 可变高度的卡片布局
  • 响应式可滚动内容
  • 交互式引导屏幕
  • 内容密集型仪表板

主要特点

  • 高度自适应当前页面
  • 页面之间的平滑过渡
  • 跨平台兼容性
  • 与 PageView 的简单集成
  • 支持嵌套滚动视图

适合对象

  • 具有可变高度页面的应用程序
  • 寻求响应式滚动行为的开发者
  • 需要自适应UI布局的项目
  • 具有动态内容的移动和网络应用
  • 希望获得灵活滚动体验的UI设计师

使用建议

  • 可能会影响大量内容下的性能
  • 需要仔细处理滚动物理效果
  • 不适合固定高度的页面设计
  • 超出高度调节之外的自定义功能有限
  • 最好与可预测的页面内容大小一起使用

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

expandable_page_view

A PageView widget adjusting its height to currently displayed page. It accepts the same parameters as classic PageView.

Horizontal Vertical

Getting Started

In the pubspec.yaml of your flutter project, add the following dependency:

dependencies:
  ...
  expandable_page_view: ^1.0.17

Import it:

import 'package:expandable_page_view/expandable_page_view.dart';

Usage Examples

Fixed Expandable Page View

In order to create a fixed page view just pass a list of widgets to children parameter:

ExpandablePageView(
  children: [
     ExamplePage(Colors.blue, "1", 100),
     ExamplePage(Colors.green, "2", 200),
     ExamplePage(Colors.red, "3", 300),
  ],
),
Dynamically built Expandable Page View

If You have multiple pages to display, and You want to build them dynamically while scrolling, use .builder constructor and pass itemCount and itemBuilder parameters:

ExpandablePageView.builder(
  itemCount: 3,
  itemBuilder: (context, index) {
    return ExamplePage(Colors.blue, index.toString(), (index + 1) * 100.0);
  },
),
Loop Mode

To create an infinitely scrolling page view, set loop: true:

ExpandablePageView(
  loop: true,
  children: [
    ExamplePage(Colors.blue, "1", 100),
    ExamplePage(Colors.green, "2", 200),
    ExamplePage(Colors.red, "3", 300),
  ],
),
Programmatic Control in Loop Mode

To programmatically navigate pages in loop mode (e.g., for auto-play carousels or custom indicators), use ExpandablePageController:

final controller = ExpandablePageController(itemCount: 3);

ExpandablePageView(
  controller: controller,
  loop: true,
  children: [
    ExamplePage(Colors.blue, "1", 100),
    ExamplePage(Colors.green, "2", 200),
    ExamplePage(Colors.red, "3", 300),
  ],
),

// Navigate programmatically
controller.jumpToPage(2);
controller.animateToPage(0, duration: Duration(milliseconds: 300), curve: Curves.ease);

// Read current page
print(controller.page);     // e.g., 1.5 (fractional during scroll)
print(controller.realPage); // e.g., 1 (rounded)

Note: ExpandablePageController uses shortest-path navigation — animating from page 0 to the last page will scroll backward (1 step) rather than forward through all pages.

Check out example project to play with ExpandablePageView.

所属分类

源码仓库

使用此插件的项目