gpt4 book ai didi

flutter - 在flutter中选择IconButton时如何创建动画

转载 作者:行者123 更新时间:2023-12-03 04:12:53 27 4
gpt4 key购买 nike

我刚刚创建了一个简单的可选2 IconButton作为以下代码:

class _RadioBtnSimState extends State<RadioBtnSim> {
bool _isSelectedLeftButton = true;
bool _isSelectedRightButton = false;

Widget build(BuildContext context) {
return Center(
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Column(
children: [
Ink(
height: _isSelectedLeftButton ? 80.0 : 60.0,
width: _isSelectedLeftButton ? 80.0 : 60.0,
decoration: ShapeDecoration(
color: _isSelectedLeftButton
? Colors.green.withOpacity(0.50)
: Colors.grey.withOpacity(0.50),
shape: CircleBorder(),
),
child: IconButton(
icon: Icon(Icons.sim_card),
color: Colors.white,
iconSize: _isSelectedLeftButton ? 40.0 : 30.0,
onPressed: () {
setState(() {
_isSelectedLeftButton = true;
_isSelectedRightButton = false;
});
},
),
),
Text(
'Sim 1',
style: _isSelectedLeftButton
? TextStyle(color: Colors.green)
: TextStyle(color: Colors.grey),
),
],
),
SizedBox(
width: 20.0,
),
Column(
children: [
Ink(
height: _isSelectedRightButton ? 80.0 : 60.0,
width: _isSelectedRightButton ? 80.0 : 60.0,
decoration: ShapeDecoration(
color: _isSelectedRightButton
? Colors.green.withOpacity(0.50)
: Colors.grey.withOpacity(0.50),
shape: CircleBorder(),
),
child: IconButton(
icon: Icon(Icons.sim_card),
color: Colors.white,
iconSize: _isSelectedRightButton ? 40.0 : 30.0,
onPressed: () {
setState(() {
_isSelectedLeftButton = false;
_isSelectedRightButton = true;
});
},
),
),
Text(
'Sim 2',
style: _isSelectedRightButton
? TextStyle(color: Colors.green)
: TextStyle(color: Colors.grey),
),
],
),
],
),
);
}
}
现在我需要的是,我想在选择 IconButton时创建一个简单的动画...
有没有简便的方法可以做到这一点?

最佳答案

为了方便调整大小和其他许多动画,可以使用animatedContainer,但是如果要使用复杂的动画,则必须使用animationControlleranimatedWidget

关于flutter - 在flutter中选择IconButton时如何创建动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63548164/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com