【问题标题】:How can I change the size of this flutter Material Button?如何更改此颤动材质按钮的大小?
【发布时间】:2021-05-23 04:12:07
【问题描述】:

我想更改按钮的大小,方法是减小垂直大小,使其有点挤压。 我写的当前代码是这样的:

        Padding(
                padding: const EdgeInsets.all(8),
                child: Material(
                  color: Color(0xFF3E4685),
                  borderRadius: BorderRadius.circular(20),
                  elevation: 6,
                  child: MaterialButton(
                    height: 0,
                    onPressed: () {},
                    padding: EdgeInsets.symmetric(vertical: 0),
                    child: Icon(
                      Icons.arrow_right_alt_sharp,
                      size: 50,
                      color: Colors.white,
                    ),
                  ),
                ),
              )

输出是这样的: Button

我希望它更窄一些,因此垂直高度更小,我尝试使用 height 属性,但它不起作用。

【问题讨论】:

    标签: flutter flutter-layout flutter-test


    【解决方案1】:

    试试这个

    SizedBox(
      width: 150,
      height: 150,
      child: Material(
       color: Color(0xFF3E4685),
       borderRadius: BorderRadius.circular(20),
       elevation: 6,
       child: MaterialButton(
        height: 0,
        onPressed: () {},
        padding: EdgeInsets.symmetric(vertical: 0),
        child: Icon(
          Icons.arrow_right_alt_sharp,
          size: 50,
          color: Colors.white,
         ),
        ),
      ),
    

    或者你可以使用ButtonTheme

    ButtonTheme(
      minWidth: 200.0,
      height: 100.0,
      child: YourButton
    ),
    

    【讨论】:

      猜你喜欢
      • 2018-12-03
      • 1970-01-01
      • 2019-06-28
      • 1970-01-01
      • 2020-11-20
      • 2020-04-12
      • 2021-07-12
      • 2020-01-21
      相关资源
      最近更新 更多