如何在 Flutter 中设置按钮的宽度和高度? [英] How to set the width and height of a button in Flutter?

查看:22
本文介绍了如何在 Flutter 中设置按钮的宽度和高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现我无法在 Flutter 中设置 ElevatedButton 的宽度.如果我很好理解的话,我应该把 ElevatedButton 放到一个 SizedBox 中.然后我将能够设置框的宽度或高度.这是正确的吗?还有其他方法吗?

I have seen that I can't set the width of a ElevatedButton in Flutter. If I have well understood, I should put the ElevatedButton into a SizedBox. I will then be able to set the width or height of the box. Is it correct? Is there another way to do it?

在每个按钮周围创建一个 SizedBox 有点乏味,所以我想知道他们为什么选择这样做.我很确定他们有充分的理由这样做,但我不明白.对于初学者来说,脚手架很难阅读和构建.

This is a bit tedious to create a SizedBox around every buttons so I'm wondering why they have chosen to do it this way. I'm pretty sure that they have a good reason to do so but I don't see it. The scaffolding is pretty difficult to read and to build for a beginner.

new SizedBox(
  width: 200.0,
  height: 100.0,
  child: ElevatedButton(
    child: Text('Blabla blablablablablablabla bla bla bla'),
    onPressed: _onButtonPressed,
  ),
),

推荐答案

如文档中所述 这里

凸起按钮的最小尺寸为 88.0 x 36.0被 ButtonTheme 覆盖.

Raised buttons have a minimum size of 88.0 by 36.0 which can be overidden with ButtonTheme.

你可以这样做

ButtonTheme(
  minWidth: 200.0,
  height: 100.0,
  child: RaisedButton(
    onPressed: () {},
    child: Text("test"),
  ),
);

这篇关于如何在 Flutter 中设置按钮的宽度和高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆