Skip to content

Instantly share code, notes, and snippets.

@saturngod
Created June 19, 2022 03:36
Show Gist options
  • Save saturngod/b4bb479e3ac86760a963c39b5fc44c77 to your computer and use it in GitHub Desktop.
Save saturngod/b4bb479e3ac86760a963c39b5fc44c77 to your computer and use it in GitHub Desktop.
Animation Add Close
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,
),
),
),
)));
}
}
@saturngod
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment