gpt4 book ai didi

flutter - 如何在 TextButton 上设置最小宽度(不更改最小高度)

转载 作者:行者123 更新时间:2023-12-04 15:15:16 33 4
gpt4 key购买 nike

假设我有这个 TextButton :

TextButton(
style: TextButton.styleFrom(
minimumSize: const Size(newWidth, newHeight),
),
onPressed: _onTapped,
child: const Text('Button'),
),
有没有办法设置最小宽度 同时保留最小高度 ?
这里的动机是保持主题的值(value)并只覆盖我需要的东西。
我希望 TextButton.defaultStyleOf(context)会很有帮助,因为它不是静态方法。
一些注意事项:
我不打算使用旧的 Material 按钮,如 FlatButton因为它们被新按钮取代(在这种情况下为 TextButton),这就是我首先提出这个问题的原因。
但是,如果有办法通过 MaterialButton 实现这一点的话,那就足够了。

最佳答案

使用 MediaQuery 获取比例大小。
文本按钮(onPressed:()
{

            },
style: TextButton.styleFrom(
primary: Colors.white,
backgroundColor: Colors.teal,
onSurface: Colors.grey,
minimumSize: Size(MediaQuery.of(context).size.width-20,40)
),
child: Text("Button")),
默认情况下,它根据其文本宽度采用宽度或者您可以尝试使用 MediaQuery

关于flutter - 如何在 TextButton 上设置最小宽度(不更改最小高度),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64443793/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com