Untitled

mail@pastecode.io avatar
unknown
dart
a year ago
1.5 kB
1
Indexable
Never
class _MyHomePageState extends State
   with SingleTickerProviderStateMixin {
 late AnimationController _controller;
 int counter = 0;


 void _onPressed() {
   setState(() {
     counter++;
   });
   _controller.forward(from: 0.0);
 }


 @override
 void initState() {
   _controller = AnimationController(
       vsync: this, duration: const Duration(milliseconds: 600));
   super.initState();
 }




 @override
 void dispose() {
   _controller.dispose();
   super.dispose();
 }


 @override
 Widget build(BuildContext context) {
   return Scaffold(
     floatingActionButton: FloatingActionButton(
       onPressed: _onPressed,
       splashColor: Colors.lightBlue.shade200,
       backgroundColor: Colors.blue,
       child: Icon(
         Icons.flip,
         color: Colors.white,
       ),
     ),
     body: AnimatedBuilder(
       animation: _controller,
       builder: (_, child) => Transform(
         alignment: Alignment.center,
         transform: Matrix4.identity()
           ..setEntry(3, 2, 0.001)
           ..rotateY(360 * _controller.value * (pi / 180.0)),
         child: LogoWidget(
           counter: counter,
         ),
       ),
     ),
   );
 }
}


class LogoWidget extends StatelessWidget {
 final int counter;


 const LogoWidget({Key? key, required this.counter}) : super(key: key);


 @override
 Widget build(BuildContext context) {
   print(' Rebuilding Widget');
   return Center(
     child: SizedBox(height: 100, width: 100, child: FlutterLogo()),
   );
 }
}