GridView会自动将行高设置为最高的网格项目 [英] GridView which automatically sets row height to the tallest grid item

查看:70
本文介绍了GridView会自动将行高设置为最高的网格项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

标题是我要实现的目标的简化版本:GridView,它根据我提供的原型网格项目自动设置行高.原型项目是可能的最高项目,例如,如果网格项目包含文本,则原型将包含可能的最长文本.

The title is a simplified version of what I'm trying to achieve: a GridView which automatically sets row height based on a prototype grid item that I supply. The prototype item is a tallest possible item, for example if the grid items contain text, the prototype would contain a longest possible text.

可能的解决方法是ListView,其中每行都包装在IntrinsicHeight小部件中.但是:

A possible workaround is a ListView in which each row is wrapped in an IntrinsicHeight widget. But:

  • 行高并不一定像GridView中一样.
  • 根据文档,
  • IntrinsicHeight效率很低.虽然不确定多少,但对于简单的布局来说可以忽略不计.理想情况下,只对一个原型行调用此计算固有高度"操作.

推荐答案

要根据馈入网格项目的项目设置自定义行高,您可以考虑使用此

For setting custom row heights depending upon the item that is fed into the grid item you can consider using this flutter_staggered_grid_view plugin.

它为普通网格和条形网格提供了不同的小部件,并将处理输入的随机大小.因此,无论您将什么尺寸的小部件馈送到网格,它都将占用该项目的大小

It provides different widgets for both normal grids and sliver grids and will take care of the random size of input. So whatever size of widget you feed to the grid it'll take the size of the item

这篇关于GridView会自动将行高设置为最高的网格项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆