【问题标题】:How change l backgroundcolor of button theme,text color and height in flutter?如何在颤动中更改按钮主题的背景颜色、文本颜色和高度?
【发布时间】:2019-12-25 05:21:26
【问题描述】:

我在我的项目中使用 Button 主题,我无法更改背景颜色、文本颜色,也无法降低按钮主题的高度,有人可以看看它。

这是我的代码:

Widget _signInButton() {


    return ButtonTheme(

     minWidth: 325,

      child: OutlineButton(
        splashColor: Colors.grey,
        onPressed: () {
          signInWithGoogle().whenComplete(() {
            Navigator.of(context).push(
              MaterialPageRoute(
                builder: (context) {
                  return FirstScreen();
                },
              ),
            );
          });
        },
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
        highlightElevation: 0,
        borderSide: BorderSide(color: Colors.grey),
        child: Padding(
          padding: const EdgeInsets.fromLTRB(0, 10, 0, 10),
          child: Row(
            mainAxisSize: MainAxisSize.min,
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Flexible(
                  flex: 1,
                  child: Image(image: AssetImage("Assets/google_logo.png"), height: 35.0)),
              Expanded(
                flex: 1,
                child: Padding(
                  padding: const EdgeInsets.only(left: 10),
                  child: Text(
                    'Sign in with Google',
                    style: TextStyle(
                      fontSize: 15,
                      color: Colors.grey,

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    尝试在ButtonTheme 中添加height: 8.0layoutBehavior:ButtonBarLayoutBehavior.constrained。 使用这些选项中的任何一个,您都可以调整按钮的高度和内边距。

    注意:请随意调整高度值。我以8.0为例

    您可以使用ButtonTheme 中的buttonColor 属性来更改按钮的颜色。或者子按钮中的 color 属性应该可以完成这项工作。

    但由于您使用的是OutlineButton,因此它无法工作,因为它没有可以绘制颜色的区域,它只有一个轮廓。

    注意: 您应该将OutlineButton 替换为RaisedButton

    对于文本颜色,您可以使用Text 小部件的style 属性。

    一个小示例代码如下:

    ButtonTheme(
    height: 8.0,
    buttonColor: Colors.red,
    child: RaisedButton(
             color: Colors.blue,
             child: Text(
               'Button',
               style: TextStyle(color: Colors.white),
              ),
              onPressed: () {},
           ),
    )
    

    【讨论】:

    • 你能告诉我如何改变按钮颜色
    • 另外,如果它对您有用并解决了您的问题,请花一些时间投票并接受答案。
    猜你喜欢
    • 2021-06-07
    • 2020-11-07
    • 2020-09-25
    • 1970-01-01
    • 2017-08-31
    • 1970-01-01
    • 2013-10-24
    • 2018-12-25
    • 2021-12-14
    相关资源
    最近更新 更多