搜尋套件、儲存庫與 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

所屬分類

原始碼儲存庫

使用此套件的專案