英文:
Flutter, how to remove spaces around text in a TextButton?
问题
padding: EdgeInsets.zero
似乎不起作用。
英文:
As titled, padding: EdgeInsets.zero
doesn't seem to work.
Container(
height: 30,
width: 60,
padding: EdgeInsets.zero,
decoration: BoxDecoration(
color: Colors.green, borderRadius: BorderRadius.circular(6)),
child: Padding(
padding: EdgeInsets.zero,
child: TextButton(
child: Text('Login', style: TextStyle(fontSize: 14, color: Colors.white)),
onPressed: () {},
),
),
),
答案1
得分: 1
你可以这样做。无需使用容器
ElevatedButton(
onPressed: () {},
child: Text('Login', style: TextStyle(fontSize: 18)),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.green),
padding: MaterialStateProperty.all(EdgeInsets.zero),
),
),
你还可以通过将minimumSize
添加到ButtonStyle
来更改小部件的最小尺寸。例如:
minimumSize: MaterialStateProperty.all(Size(10, 10)),
这将使最小尺寸为10x10,如果你的文本尺寸足够小的话。但要记住,你也需要能够轻松按下按钮。
还可以查看这个链接:
https://api.flutter.dev/flutter/material/ButtonStyle-class.html
英文:
From your comment:
> The text Login doesn’t fully shown, I would like to maintain the size of the green box, while making the size of the text inside as big as possible.
You can do that like this. No need for Containers
ElevatedButton(
onPressed: () {},
child: Text('Login', style: TextStyle(fontSize: 18)),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.green),
padding: MaterialStateProperty.all(EdgeInsets.zero),
),
),
You can also change the minimum size of the widget by adding minimumSize
to the ButtonStyle
. For example:
minimumSize: MaterialStateProperty.all(Size(10, 10)),
This will make the minimum size 10x10, if your text size is small enough.
But keep in mind that you need to be able to easily press the button too.
Also check this:
https://api.flutter.dev/flutter/material/ButtonStyle-class.html
答案2
得分: 0
尝试这样做:将您的容器包装在此中:
MediaQuery.removePadding(
context: context,
removeTop: true,
removeBottom: true,
child: Container(....)
)
英文:
Try this: Wrap your container in this
MediaQuery.removePadding(
context:context,
removeTop:true,
removeBottom:true,
child: Container(....)
)
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论