我试图改变图标的形状和颜色的图标按钮时,它被按下,但没有发生任何事情。下面是我的代码:
String adTitle = widget.documentSnapshot['Title'];
String $adDescription = widget.documentSnapshot['Description'];
IconData _iconData = Icons.favorite_border_outlined;
Color _iconColor = Colors.red;
return Scaffold(
body: Column(
children: [
Row(
children: [
IconButton.outlined(
icon: Icon(
_iconData,
size: 40,
color: _iconColor,
),
onPressed: () {
setState(() {
_iconData = Icons.favorite;
_iconColor = Colors.blue;
});
},
)
],
),
],
),
);
}
1条答案
按热度按时间wtzytmuj1#
它们现在是局部变量。你需要把它们变成类级别的变量(在构建方法之外定义它们)