“The named parameter ‘color’ isn’t defined for the ‘ElevatedButton’ flutter.”

huangapple go评论50阅读模式
英文:

The named parameter 'color' isn't defined. for the 'ElevatedButton' flutter

问题

我正在开发一个基于Flutter的移动应用项目。在我创建的页面上,我放置了一个具有重定向功能的按钮。但当我尝试设置按钮的颜色时,出现了错误:未定义命名参数'color'。

我的上述代码如下:

Center(
child: ElevatedButton(
onPressed: () {
// 在此处添加重定向功能
},
child: const Text(
'具有重定向功能的按钮',
style: TextStyle(
color: Colors.white,
),
),
style: ElevatedButton.styleFrom(
color: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32.0),
),
),

  ),

),


我尝试使用不同的对象来使用color参数,但仍然遇到相同的错误。
英文:

I am working on a mobile app project on Flutter. In the page I have created, I put a button with redirect functionality. But when I try to paint the button it raises an error : The named parameter 'color' isn't defined.

            Center( 
                child: ElevatedButton(
                   onPressed: () {
                    // add your redirect functionality here
                   },                
                   child: const Text(
                     'Button with redirect functionality',
                     style: TextStyle(
                       color: Colors.white,
                      ),
                    ),
                    style: ElevatedButton.styleFrom(
                      color: Colors.blue,
                      shape: RoundedRectangleBorder(
                         borderRadius: BorderRadius.circular(32.0),
                      ),
                    ),
                              
                  ),
              ),

My source code for the mentioned buttoned is above. I would be appreciated and grateful If someone tell what is going wrong with that

Thank you so much for your interest

I have tried to do use the color parameter with different objects but got the same error

答案1

得分: 1

Use the property "backgroundColor".
像这样:

Center(
      child: ElevatedButton(
        onPressed: () {
          // 在这里添加重定向功能
        },
        child: const Text(
          '具有重定向功能的按钮',
          style: TextStyle(
            color: Colors.white,
          ),
        ),
        style: ElevatedButton.styleFrom(
           backgroundColor: Colors.blue,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(32.0),
          ),
        ),
      ),
    )
英文:

Use the property "backgroundColor".
Like this:

Center(
      child: ElevatedButton(
        onPressed: () {
          // add your redirect functionality here
        },
        child: const Text(
          'Button with redirect functionality',
          style: TextStyle(
            color: Colors.white,
          ),
        ),
        style: ElevatedButton.styleFrom(
           backgroundColor: Colors.blue,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(32.0),
          ),
        ),
      ),
    )

huangapple
  • 本文由 发表于 2023年4月13日 19:51:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76005087.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定