(Flutter)图标动画
CODE
import 'package:flutter/material.dart';
void main() {
return runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage>
with SingleTickerProviderStateMixin {
late AnimationController _animationController;
@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: Duration(seconds: 1),
);
_animationController.reverse();
}
bool ifPlaying = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: GestureDetector(
onTap: (){
ifPlaying = !ifPlaying;
if (ifPlaying) {
_animationController.forward();
} else {
_animationController.reverse();
}
},
child: AnimatedIcon(
icon: AnimatedIcons.play_pause,
progress: _animationController,
size: 150,
),
),
));
}
}
预览

License:
CC BY 4.0