flutter - 我无法更改 ElevatedButton 的颜色。扑
问题描述
问题是什么?
该按钮位于渐变的背景上并采用其颜色,但我无法更改颜色。
也许问题出在渐变中?虽然我试图去除容器的装饰,但没有帮助。也许它是一个容器?
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Colors.black, Colors.blue]),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(...),
CircularPercentIndicator(...),
Padding(...),
SizedBox(height: 20),
Padding(
padding: EdgeInsets.only(bottom: 30.0),
child: ElevatedButton(
child: Text("Start destroying"),
onPressed: null,
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
primary: Colors.black,
padding: EdgeInsets.symmetric(horizontal: 60, vertical: 15),
textStyle: TextStyle(
fontSize: 25,
color: Colors.white,
),
),
),
),
],
),
),
);
}
解决方案
您需要为以下设置一个非空onPressed
函数ElevatedButton
:
ElevatedButton(
child: Text("Start destroying"),
onPressed: () {}, // add this
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
primary: Colors.red,
padding: EdgeInsets.symmetric(horizontal: 60, vertical: 15),
textStyle: TextStyle(
fontSize: 25,
color: Colors.white,
),
),
),
推荐阅读
- javascript - 如何将下载链接添加到此脚本的第二个图像中
- html - 如何为行的顶部和底部边框线赋予颜色属性
- sql - 按顺序显示sql xml数据
- python - 在 QGraphicsItem 中使用 QPainterPath 检测鼠标命中
- dm-script - dm脚本中零均值归一化互相关的计算
- node.js - 在 vagrant 中将 Node.js 连接到 apache 服务器上的 postgres
- c# - 如何拥有多个身份验证处理程序 asp.net core 2.0
- java - 如何使用java代码和pdfbox从pdf文件中提取参数
- python - 重构建议
- vue.js - 如何为 Vue 项目添加 url 配置文件