如何在Flutter应用中减少迭代行中的间距

huangapple go评论62阅读模式
英文:

How to reduce Spacing in an iterated row in Flutter Application

问题

在我的Flutter项目中,我正在尝试减少行之间不必要的间距。我有以下在Flutter项目中的UI:

for (final stuff in stuffs)
  if (stuff.item == item.id)
    Row(
      children: <Widget>[
        const Expanded(
          flex: 1,
          child: Text('Order: '),
        ),
        Expanded(
          flex: 1,
          child: ListTile(
            title: Text(stuff.order.toString()),
          ),
        ),
        const Expanded(
          flex: 1,
          child: Text('Reps: '),
        ),
        Expanded(
          flex: 1,
          child: ListTile(
            title: Text(stuff.repetitions.toString()),
          ),
        ),
        IconButton(
          icon: const Icon(Icons.edit),
          onPressed: () async {},
        ),
        IconButton(
          icon: Icon(Icons.delete),
          onPressed: () async {},
        ),
      ],
    ),

这是当前的结果:

如何在Flutter应用中减少迭代行中的间距

我的问题和目标是如何减少每次迭代之间的间距。我想尽量将它减小,以减少不必要的间距。

英文:

In my Flutter project I am trying to reduce unecessary spacing after the rows
I have the following UI in a flutter project

  for (final stuff in stuffs)
    if (stuff.item == item.id)
	Row(
		children: &lt;Widget&gt;[
		  const Expanded(
			flex: 1,
			child: Text(&#39;Order: &#39;),
		  ),
		  Expanded(
			flex: 1,
			child: ListTile(
			  title: Text(stuff.order.toString()),
			),
		  ),
		  const Expanded(
			flex: 1,
			child: Text(&#39;Reps: &#39;),
		  ),
		  Expanded(
			flex: 1,
			child: ListTile(
			  title: Text(stuff.repetitions.toString()),
			),
		  ),
		  IconButton(
			icon: const Icon(Icons.edit),
			onPressed: () async {},
		  ),
		  IconButton(
			icon: Icon(Icons.delete),
			onPressed: () async {},
		  ),
		],
	),

This is the current outcome:
如何在Flutter应用中减少迭代行中的间距

My question and objective is how to reduce the spacing between each iteration. I want to minimize it as much as possible to reduce uneeded spacing

答案1

得分: 1

你可以尝试将Row widget包裹在一个高度较小的SizedBox小部件中。

SizedBox(
  height: 30, // 根据需要调整高度
  child: Row(
    children: <Widget>[
      // ...
    ],
  ),
),
英文:

you can try wrapping the Row widget in a SizedBox widget with a smaller height.

SizedBox(
  height: 30, // adjust the height as needed
  child: Row(
    children: &lt;Widget&gt;[
      // ...
    ],
  ),
),

答案2

得分: 0

ListTile具有默认的高度,对于您的情况,您可以删除ListTile小部件。还请检查IconButton上的填充,您可能只需要InkWell

英文:

ListTile comes with default height, For your case you can remove ListTile widget. Also Check padding on IconButton, you may just need InkWell

  double get _defaultTileHeight {
    final bool hasSubtitle = subtitle != null;
    final bool isTwoLine = !isThreeLine &amp;&amp; hasSubtitle;
    final bool isOneLine = !isThreeLine &amp;&amp; !hasSubtitle;

    final Offset baseDensity = visualDensity.baseSizeAdjustment;
    if (isOneLine) {
      return (isDense ? 48.0 : 56.0) + baseDensity.dy;
    }
    if (isTwoLine) {
      return (isDense ? 64.0 : 72.0) + baseDensity.dy;
    }
    return (isDense ? 76.0 : 88.0) + baseDensity.dy;
  }

huangapple
  • 本文由 发表于 2023年3月7日 10:59:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/75657659.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定