[英]Flutter- Change animated icon color for opening(white) and closing(red)
I'm using animated icon for open and closing side menu into my app.我正在使用动画图标在我的应用程序中打开和关闭侧边菜单。 I need to change the closing icon color Red and opening icon color will be white.
我需要将关闭图标颜色更改为红色,打开图标颜色将为白色。
AnimatedIcon(
progress: _animationController.view,
icon: menuClose,
color: menuIconColor, >need to apply condition here
size: 25.sp,
)
Full code of the button are given below按钮的完整代码如下
Align(
alignment: Alignment(0, .99),
child: GestureDetector(
onTap: () {
onIconPressed();
},
child: ClipRRect(
borderRadius: BorderRadius.circular(80),
child: Container(
width: 50.w,
height: 45.h,
color: colorAnimatedButton,
alignment: Alignment.center,
child: AnimatedIcon(
progress: _animationController.view,
icon: menuClose,
color: iconColor,
size: 25.sp,
),
),
),
),
)
Try with this code i used null safety sdk.尝试使用此代码,我使用了 null 安全 sdk。
class AnimIconTest extends StatefulWidget {
const AnimIconTest({Key? key}) : super(key: key);
@override
_AnimIconTestState createState() => _AnimIconTestState();
}
class _AnimIconTestState extends State<AnimIconTest>
with TickerProviderStateMixin {
late AnimationController _animationController;
@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: Duration(milliseconds: 400),
);
}
Color iconColor = Colors.white;
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.blueAccent,
body: Center(
child: InkWell(
onTap: () {
if (_animationController.status == AnimationStatus.completed) {
_animationController.reverse();
setState(() {
iconColor = Colors.white;
});
} else {
_animationController.animateTo(1.0);
setState(() {
iconColor = Colors.red;
});
}
},
child: AnimatedIcon(
progress: _animationController,
icon: AnimatedIcons.menu_close,
color: iconColor,
),
),
),
),
);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.