flutter MenuItemButton:如何限制其扩展并删除左边距?

问题描述 投票:0回答:1
  Column(children: [
    Row(children: [
      SizedBox(width: 200,
        child: Text('Name')),
      Flexible(
        child: Text('John')),
      ),
    ],

    Row(children: [
      SizedBox(width: 200,
        child: Text('Order Id')),
      Flexible(
        child: MenuItemButton(
          child: Text('123456')),
      ),
    ],
  ]);

MenuItemButton 展开以占据行中的所有可用空间。它具有左填充/边距,因此不会与同一列中的其他值对齐。

 Name     | John
-----------------------------
 Order Id |   123456        |

如何让 MenuItemButton 具有适合其子项的宽度?如何删除其左侧填充以与“John”对齐?

尝试过:

MenuItemButton(
  style: const ButtonStyle(
      tapTargetSize: MaterialTapTargetSize.shrinkWrap,
      minimumSize: MaterialStatePropertyAll(Size(0, 0))),
  child: Text('123456'))
flutter
1个回答
0
投票

左侧填充来自 TextButtonStyle 的默认填充,可以使用

style

进行操作
 MenuItemButton(
  style: ButtonStyle(
    padding: MaterialStatePropertyAll(
      EdgeInsets.all(0),
    ),
  ),
  child: Text('123456'),
© www.soinside.com 2019 - 2024. All rights reserved.