如何在Flutter中设置RaisedButton的宽度? [英] How to set the width of a RaisedButton in Flutter?

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

问题描述

我已经看到我无法在Flutter中设置RaisedButton的宽度.如果我很了解,我应该将RaisedButton放入SizedBox中.然后,我将能够设置盒子的宽度或高度.这是正确的吗?还有另一种方法吗?

I have seen that I can't set the width of a RaisedButton in Flutter. If I have well understood, I should put the RaisedButton 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: new RaisedButton(
    child: new 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中设置RaisedButton的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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