【问题标题】:Flutter Change Button Color颤振更改按钮颜色
【发布时间】:2021-11-24 14:12:10
【问题描述】:

有什么建议可以改变下方 ElevateButton 的颜色吗?

child: ElevatedButton(
                                child: Text(
                                  'Subscribe',
                                  style: TextStyle(
                                      color: gray900,
                                      fontFamily: 'Lexend Exa',
                                      fontSize: 20),
                                ),
                                onPressed: fetchOffersMonthly,
                              ),

【问题讨论】:

标签: flutter flutter-layout


【解决方案1】:

试试下面的代码希望它对你有帮助。 ElevatedButton

参考文档Here
ElevatedButton(
       style: ElevatedButton.styleFrom(
                 primary: Colors.red,//choose your color on your need
                ),
           child: Text(
            'Subscribe',
               style: TextStyle(
                 color: gray900,
                  fontFamily: 'Lexend Exa',
                  fontSize: 20),
                ),
                onPressed: fetchOffersMonthly,
              ),

您的结果屏幕 ->

【讨论】:

    【解决方案2】:

    使用ButtonStyle改变颜色

     ElevatedButton(
        style: ButtonStyle(
        backgroundColor: MaterialStateProperty.all<Color>(Colors.green)),
        onPressed: () {  }, 
        child: Text(""),
     ),
    

    【讨论】:

      【解决方案3】:
      ElevatedButton(
              child: Text('Subscribe'),
              onPressed: () {},
              style: ElevatedButton.styleFrom(
                  primary: Colors.purple,
                  textStyle: TextStyle(
                    fontSize: 30,
                    fontWeight: FontWeight.bold),
            ),
          )
      

      【讨论】:

      • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
      • 虽然此代码可能会回答问题,但提供有关它如何和/或为什么解决问题的额外上下文将提高​​答案的长期价值。您可以在帮助中心找到更多关于如何写好答案的信息:stackoverflow.com/help/how-to-answer。祝你好运?
      猜你喜欢
      • 1970-01-01
      • 2018-06-05
      • 2021-08-19
      • 2020-09-27
      • 1970-01-01
      • 1970-01-01
      • 2020-09-25
      • 1970-01-01
      • 2021-12-26
      相关资源
      最近更新 更多