我正在使用影片圖示在我的應用程式中打開和關閉側邊選單。我需要將關閉圖示顏色更改為紅色,打開圖示顏色將為白色。
AnimatedIcon(
progress: _animationController.view,
icon: menuClose,
color: menuIconColor, >need to apply condition here
size: 25.sp,
)
按鈕的完整代碼如下
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,
),
),
),
),
)
uj5u.com熱心網友回復:
嘗試使用此代碼,我使用了 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,
),
),
),
),
);
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/407083.html
標籤:
