[英]I can't change the color of the ElevatedButton. Flutter
問題是什么?
該按鈕位於漸變的背景上並采用其顏色,我無法更改顏色..
也許問題出在梯度上? 雖然我試圖去除容器的裝飾,但沒有幫助。 也許它是一個容器?
@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,
),
),
),
),
],
),
),
);
}
您需要為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.