英文:
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),
),
),
),
)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论