英文:
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 {},
),
],
),
这是当前的结果:
我的问题和目标是如何减少每次迭代之间的间距。我想尽量将它减小,以减少不必要的间距。
英文:
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: <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 {},
),
],
),
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: <Widget>[
// ...
],
),
),
答案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 && hasSubtitle;
final bool isOneLine = !isThreeLine && !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;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论