【发布时间】:2020-02-19 06:14:57
【问题描述】:
我想在单击按钮时更改按钮的颜色和文本。但它没有改变。我在 setState 中更改我的变量,并使用三元运算符设置文本和颜色。 希望能帮到大家。
Container(
padding: EdgeInsets.symmetric(horizontal: 15,vertical: 15),
alignment: Alignment.bottomCenter,
child: SizedBox(
width: double.infinity, //Full width
height: 40,
child: FlatButton(
child: Text( stopSelling ? "Dejar de vender" : "Empezar a vender",style: TextStyle(fontSize: 20,fontWeight: FontWeight.w300),),
onPressed: () {
setState(() {
stopSelling = !stopSelling;
});
},
textColor: Colors.white,
color: stopSelling?Colors.red:Colors.green,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
)
),
),
【问题讨论】:
-
你在哪里初始化你的 stopSelling 变量?
标签: flutter colors widget refresh