从PopupMenuItem中删除填充(溢出菜单)

时间:2018-11-01 10:56:21

标签: dart flutter

如何从PopupMenuItem删除这16 dp的填充? enter image description here

这是我的PopupMenuItem

列表
PopupMenuItem(
  child: Text("Hello"),
  value: 0,
),
PopupMenuItem(
  child: Text("Remove padding"),
  value: 1,
),

3 个答案:

答案 0 :(得分:0)

我不喜欢它,但这是唯一对我有用的解决方案。我不得不编辑非项目文件(PopupMenuItem类)

return InkWell(
      onTap: widget.enabled ? handleTap : null,
      child: Container(
        height: widget.height,
        padding: const EdgeInsets.symmetric(horizontal: _kMenuHorizontalPadding), // setting this to 0 worked 
        child: item,
      ),
    );

PS:我希望有人会提出更好的答案。我将很高兴接受它。谢谢:)

答案 1 :(得分:0)

enter image description here

在我的情况下,我必须除去固定的填充垫8,该填充垫将我所有的组件都移到了侧面,并且感觉不太好。为此,我创建了一种适用于我的情况的解决方法。当我在“行”上工作时,这对我来说已经足够了:

0777

如您所见,我已在ConstrainedBox中强制设置了最大高度和宽度。实际上,填充现在对此没有影响。

答案 2 :(得分:-2)

您的PopupMenuItems应该在PopupMenuButton widget which has a padding property set to 8dp by default之内。尝试将值更改为所需的值。