[英]I can't change the color of the ElevatedButton. Flutter
What is the problem?问题是什么?
The button is located on the background of the gradient and takes its color and i can't change the color..该按钮位于渐变的背景上并采用其颜色,我无法更改颜色..
Maybe the problem is in the gradient?也许问题出在梯度上? Although I tried to remove the decoration of the container, it did not help.
虽然我试图去除容器的装饰,但没有帮助。 Maybe it's a container?
也许它是一个容器?
@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,
),
),
),
),
],
),
),
);
}
You need to set a non-null onPressed
function for the ElevatedButton
:您需要为
ElevatedButton
设置一个非空的onPressed
function :
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,
),
),
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.