Created
June 19, 2022 03:36
-
-
Save saturngod/b4bb479e3ac86760a963c39b5fc44c77 to your computer and use it in GitHub Desktop.
Animation Add Close
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatefulWidget { | |
@override | |
_MyAppState createState() => _MyAppState(); | |
} | |
class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin { | |
late AnimationController animatedController; | |
double _angle = 0; | |
@override | |
void initState() { | |
animatedController = | |
AnimationController(vsync: this, duration: Duration(milliseconds: 100)); | |
animatedController.addListener(() { | |
setState(() { | |
_angle = animatedController.value * 45 / 360 * pi * 2; | |
}); | |
}); | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
body: Center( | |
child: InkResponse( | |
onTap: () { | |
if (animatedController.status == AnimationStatus.completed) | |
animatedController.reverse(); | |
else if (animatedController.status == AnimationStatus.dismissed) | |
animatedController.forward(); | |
}, | |
child: Transform.rotate( | |
angle: _angle, | |
child: Icon( | |
Icons.add, | |
size: 50, | |
), | |
), | |
), | |
))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code from https://stackoverflow.com/a/62505456/215939