简体   繁体   English

如何去除 Flutter 中 TextButton 的边距?

[英]How to remove margin from TextButton in Flutter?

I have a list of TextButtons and I need to remove the margin from around this buttons?我有一个TextButtons列表,我需要删除此按钮周围的边距吗? The gray border around text is the background of this textButtons but I need to remove space around this buttons文本周围的灰色边框是此 textButtons 的背景,但我需要删除此按钮周围的空间

TextButton(
          style: const ButtonStyle(alignment: AlignmentDirectional.centerStart),
          onPressed: () {
            AutoRouter.of(context).navigate(route);
          },
          child: Text(
            title,
            style: getCurrentStyle(),
          ));

Material Design have some rules and force standart clickable components to have a minimum area. Material Design 有一些规则并强制标准可点击组件具有最小面积。 So that users can click easily.方便用户点击。 For example IconButton also have a minimum render size.例如 IconButton 也有最小渲染尺寸。

Because of this limitations even if you apply a zero padding there will be some minimum width or height.由于此限制,即使您应用零填充,也会有一些最小宽度或高度。 You can see and inspect this effect using Dev Tools (Flutter Inspector)您可以使用 Dev Tools (Flutter Inspector) 查看和检查此效果

What you can do is just wrapping your Text Widget with GestureDetector or InkWell.您可以做的只是用 GestureDetector 或 InkWell 包装您的文本小部件。

GestureDetector(
      onTap: () {
        AutoRouter.of(context).navigate(route);
      },
      child: Text(
        title,
        style: getCurrentStyle(),
      ));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM