搜尋套件、儲存庫與 APP 分類

responsive_grid_list 封面
套件詳情v1.4.1

responsive_grid_list

一個 Flutter 外掛程式,使用 ListView.builder() 或帶有 SliverChildBuilderDelegate 的 SliverList 創建響應式網格清單。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.3萬
喜歡數
151
Pub 分數
150

安裝套件

flutter pub add responsive_grid_list

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 套件,可使用 ListView.builder() 或 SliverList 與 SliverChildBuilderDelegate 建立響應式網格清單。它會根據螢幕尺寸自動調整欄數,確保在各種裝置上都能呈現最佳版面。非常適合以流動、自適應的方式顯示圖片、卡片或產品等項目集合。此套件支援所有主要平台,包含 Android、iOS、Web、macOS、Windows 與 Linux。

適用情境

  • 顯示圖像畫廊
  • 構建產品目錄
  • 建立適應性卡片版面
  • 實現響應式儀表板
  • 渲染動態內容網格

主要特色

  • 根據螢幕尺寸自動調整欄位數
  • 支援 ListView.builder 與 SliverList
  • 跨平台相容性
  • 與現有組件的簡單整合
  • 彈性項目大小

適合對象

  • 開發響應式 UI 的開發者
  • 針對多種裝置尺寸的應用
  • 內容密集型應用
  • 需要網格一致性的設計系統

使用建議

  • 需要小心處理項目長寬比
  • 可能需要自定間距調整
  • 不適合高度複雜的網格圖案
  • 性能取決於項目複雜度
  • 僅限基本網格行為,不支援進階自訂

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Pub Version codecov style: very good analysis

Responsive Grid List

A Flutter plugin to create responsive grid lists using ListView.builder(), SliverList with a SliverChildBuilderDelegate or any other list.

The provided Widgets essentially work like a Flutter Wrap Widget but they are more performant with large lists because of the internal use of ListView.builder() functions.

The items in the grid are all the same width and have the same height per row. This means when a Card widget for example is higher because of a large description or so, the whole row will get higher. The row after that can be lower since it will be the height of it's highest child.

Screenshots

Mobile Desktop
Mobile Example Mobile Example

Usage

import 'package:responsive_grid_list/responsive_grid_list.dart';
ResponsiveGridList

A Responsive Grid List which uses ListView.builder() internally.

ResponsiveGridList(
    horizontalGridSpacing: 16, // Horizontal space between grid items
    verticalGridSpacing: 16, // Vertical space between grid items
    horizontalGridMargin: 50, // Horizontal space around the grid
    verticalGridMargin: 50, // Vertical space around the grid
    minItemWidth: 300, // The minimum item width (can be smaller, if the layout constraints are smaller)
    minItemsPerRow: 2, // The minimum items to show in a single row. Takes precedence over minItemWidth
    maxItemsPerRow: 5, // The maximum items to show in a single row. Can be useful on large screens
    listViewBuilderOptions: ListViewBuilderOptions(), // Options that are getting passed to the ListView.builder() function
    children: [...], // The list of widgets in the list
);
ResponsiveSliverGridList

A Responsive Grid List which uses SliverList with a SliverChildBuilderDelegate internally.

ResponsiveSliverGridList(
    horizontalGridSpacing: 16, // Horizontal space between grid items
    verticalGridSpacing: 16, // Vertical space between grid items
    horizontalGridMargin: 50, // Horizontal space around the grid
    verticalGridMargin: 50, // Vertical space around the grid
    minItemWidth: 300, // The minimum item width (can be smaller, if the layout constraints are smaller)
    minItemsPerRow: 2, // The minimum items to show in a single row. Takes precedence over minItemWidth
    maxItemsPerRow: 5, // The maximum items to show in a single row. Can be useful on large screens
    sliverChildBuilderDelegateOptions: SliverChildBuilderDelegateOptions(), // Options that are getting passed to the SliverChildBuilderDelegate() function
    children: [...], // The list of widgets in the list
);
ResponsiveGridListBuilder

A Responsive Grid List which offers a builder in which every List / Column can be used with this package.

ResponsiveGridListBuilder(
    horizontalGridSpacing: 16, // Horizontal space between grid items
    verticalGridSpacing: 16, // Vertical space between grid items
    horizontalGridMargin: 50, // Horizontal space around the grid
    verticalGridMargin: 50, // Vertical space around the grid
    minItemWidth: 300, // The minimum item width (can be smaller, if the layout constraints are smaller)
    minItemsPerRow: 2, // The minimum items to show in a single row. Takes precedence over minItemWidth
    maxItemsPerRow: 5, // The maximum items to show in a single row. Can be useful on large screens
    gridItems: [...], // The list of widgets in the grid
    builder: (context, items) {
      // Place to build a List or Column to access all properties.
      // Set [items] as children attribute for example.
    }
);

Extending AbstractResponsiveGridList

To create a Responsive Grid you can extend the AbstractResponsiveGridList class and access the getResponsiveGridListItems(double maxWidth) function to generate the grid and pipe it into your custom list.

class MyResponsiveGridList extends AbstractResponsiveGridList{
   /// Constructor etc...
  [...]

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (BuildContext context, BoxConstraints constraints) {

        // The abstract class has a function to generate the grid from
        // the constructor's paramters and the layout constraints max width
        var items = getResponsiveGridListItems(constraints.maxWidth);

        return [...]
      },
    );
  }
}

Future Features

  • [x] Optional padding at the edges of the grid
  • [x] Tests
  • [ ] Optional delta in which the width of the children can vary instead of setting the just the minimum width
  • [ ] Option to constrain the height of the items to a fixed value
    • Probably better to use the Flutter GridView instead. It offers aspectRatio.

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案