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

插件详情v1.2.0

flex_list

一个用于灵活列表的 Flutter 布局小部件。它在 wrap 中的行为符合您对 Expand 小部件的预期。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1810
喜欢数
30
Pub 分数
150

安装插件

flutter pub add flex_list

插件介绍

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

FlexList 是一个 Flutter 小部件,旨在创建灵活且响应式的列表,能够在布局约束内动态适应。其功能类似于 Wrap 内部的 Expand 小部件,使项目能够根据可用空间进行增长和收缩。非常适合在不同屏幕尺寸和方向上创建流畅、可扩展的列表布局,无需复杂的自定义代码即可增强 UI 的灵活性。该包支持所有主要平台,适用于需要自适应列表行为的跨平台应用程序。

适合场景

  • 响应式列表布局
  • 动态项目尺寸
  • 跨平台 UI 设计
  • 自适应内容容器
  • 灵活的网格列表
  • 嵌套布局集成

主要特点

  • 自动调整大小的列表项
  • 支持所有 Flutter 平台
  • 直观的类似包装的行为
  • 最小配置要求
  • 与现有布局无缝集成
  • 跨设备的一致性行为

适合对象

  • 开发响应式 UI 的开发者
  • 需要自适应列表设计的应用
  • 跨平台项目
  • 布局密集型应用
  • 需要动态间距的UI组件

使用建议

  • 在复杂的嵌套结构中可能需要仔细对齐
  • 处理超大数据集时的性能影响
  • 除了基本的弹性行为外,自定义选项有限
  • 不适合固定大小或刚性布局
  • 最适合中等大小的列表
  • 依赖于父容器的约束

原始 README

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

Flex List

Pub Points Pub Points Pub Points

Provides a flexible list layout that behaves as you would expect from Expand widgets within a Wrap.

Features

FlexList puts as many provided elements as possible in one row (like Wrap), but also extends the width of the elements by the remaining space per row. This means that each row is filled to the maximum width.

Getting started

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

dependencies:
  ...
  flex_list: <latest_version>

In your library add the following import:

import 'package:flex_list/flex_list.dart';

Usage

The following example shows how to use FlexList. Beside the children property, you can set horizontalSpacing and verticalSpacing to define the spacing between the elements.

Note: Both spacing values are 10 by default.

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'FlexList Demo',
        theme: ThemeData(),
        home: Scaffold(
          body: Center(
            child: SizedBox(
                width: 300,
                child: FlexList(
                  horizontalSpacing: 5,
                  verticalSpacing: 10,
                  children: [
                    for (var i = 0; i < 10; i++)
                      Container(
                        color: Theme
                            .of(context)
                            .colorScheme.surfaceContainer,
                        padding: EdgeInsets.symmetric(
                            horizontal: 20 + 20 * (i % 4), vertical: 10),
                        child: Text("Item $i"),
                      )
                  ],
                )),
          ),
        ));
  }
}
Rendering of above Example
Example Rendering

Additional information

This package was written because of the lack of such layout function. The package repository is maintained on Github and published on pub.dev

所属分类

源码仓库

使用此插件的项目