搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目