如何删除OutlinedButton中的默认填充?

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

How to remove default padding in OutlinedButton?

问题

我想要移除轮廓按钮的默认内边距。这是我的代码;

SizedBox(
    width: 150.0,
    child: OutlinedButton(
        onPressed: () {
            setState(() {
                selected = index;
            });
        },
        style: OutlinedButton.styleFrom(
            backgroundColor: (selected == index) ? color : Colors.white,
            shape: const RoundedRectangleBorder(
                borderRadius: BorderRadius.only(
                    topLeft: Radius.circular(20),
                    topRight: Radius.circular(30),
                    bottomLeft: Radius.circular(20),
                    bottomRight: Radius.circular(20),
                ),
            ),
            padding: EdgeInsets.zero, // 这里设置内边距为零
        ),
        child: Row(
            children: [
                Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                        Text(duration),
                        Text(dataPlan),
                        Text(price),
                    ],
                ),
            ],
        ),
    ),
);

这个SizedBox被包装在一个ListView中。

这是我得到的结果;

如何删除OutlinedButton中的默认填充?

我希望将左右的内边距移除,这样我就可以根据我的喜好进行自定义。谢谢。

英文:

I want to remove the default padding from an outlined button. This is my code;

SizedBox(
    width: 150.0,
    child: OutlinedButton(
      onPressed: () {
        setState(() {
          selected = index;
        });
      },
      style: OutlinedButton.styleFrom(
        backgroundColor: (selected == index) ? color : Colors.white,
        shape: const RoundedRectangleBorder(
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(20),
            topRight: Radius.circular(30),
            bottomLeft: Radius.circular(20),
            bottomRight: Radius.circular(20),
          ),
        ),
      ),
      child: Row(
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(duration),
              Text(dataPlan),
              Text(price),
            ],
          ),
        ],
      ),
    ),
  );

The SizedBox is wrapped in a ListView.

This is the result I get;

如何删除OutlinedButton中的默认填充?

I want the paddings at the left and right removed, so I can customize to my preference. Thanks.

答案1

得分: 1

Column 中添加此属性以减小小部件的大小。

Column(
  mainAxisSize: MainAxisSize.min,
  ...

如果您有任何其他需要翻译的内容,请随时提出。

英文:

Add in Column this property to reduce size of the widget.

       Column(
        mainAxisSize: MainAxisSize.min
        ...

答案2

得分: 1

将以下属性添加到按钮样式中:

tapTargetSize: MaterialTapTargetSize.shrinkWrap
minimumSize: Size.zero
padding: EdgeInsets.zero

另外,在Column和Row上设置mainAxisSize为min:

child: Row(
  mainAxisSize: MainAxisSize.min,
  children: [
    Column(
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(duration),
        Text(dataPlan),
        Text(price),
      ],
    ),
  ],
)
英文:

Add the following properties to the button style:

tapTargetSize: MaterialTapTargetSize.shrinkWrap
minimumSize: Size.zero
padding: EdgeInsets.zero

In addition, set the mainAxisSize on the Column and on the row to min:

child: Row(
  mainAxisSize: MainAxisSize.min,
  children: [
    Column(
      mainAxisSize: MainAxisSize.min,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(duration),
        Text(dataPlan),
        Text(price),
      ],
    ),
  ],
),

答案3

得分: 1

Just add minimumSize: Size.zero, padding: EdgeInsets.zero, in OutlinedButton.styleFrom().

SizedBox(
width: 150.0,
height: 100,
child: OutlinedButton(
onPressed: () {

},
style: OutlinedButton.styleFrom(
  minimumSize: Size.zero,
  padding: EdgeInsets.zero,
  backgroundColor: Colors.yellow,
  shape: const RoundedRectangleBorder(
    borderRadius: BorderRadius.only(
      topLeft: Radius.circular(20),
      topRight: Radius.circular(30),
      bottomLeft: Radius.circular(20),
      bottomRight: Radius.circular(20),
    ),
  ),
),
child: Row(
  crossAxisAlignment: CrossAxisAlignment.start,
  children: [
    Column(

      children: [
        Text("duration"),
        Text("dataPlan"),
        Text("price"),
      ],
    ),
  ],
),

)
)

英文:

Just add minimumSize: Size.zero,padding: EdgeInsets.zero, in OutlinedButton.styleFrom()

 SizedBox(
        width: 150.0,
        height:100,    
        child: OutlinedButton(
          onPressed: () {
            
          },
          style: OutlinedButton.styleFrom(
            minimumSize: Size.zero, 
           padding: EdgeInsets.zero,
            backgroundColor: Colors.yellow,
            shape: const RoundedRectangleBorder(
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(20),
                topRight: Radius.circular(30),
                bottomLeft: Radius.circular(20),
                bottomRight: Radius.circular(20),
              ),
            ),
          ),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Column(
                
                children: [
                  Text("duration"),
                  Text("dataPlan"),
                  Text("price"),
                ],
              ),
            ],
          ),
        )),

huangapple
  • 本文由 发表于 2023年2月8日 19:19:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75385018.html
匿名

发表评论

匿名网友

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

确定