Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Animation Demo',
home: Center(
child: AnimatedButton(),
),
debugShowCheckedModeBanner: false,
);
}
}
class AnimatedButton extends StatefulWidget {
@override
_AnimatedButtonState createState() => _AnimatedButtonState();
}
class _AnimatedButtonState extends State<AnimatedButton>
with SingleTickerProviderStateMixin {
AnimationController controller;
@override
void initState() {
controller = AnimationController(
duration: Duration(milliseconds: 1200), vsync: this, value: 0);
controller.addStatusListener((AnimationStatus status) {
if (status == AnimationStatus.completed) {
controller.reverse();
}
else if (status == AnimationStatus.dismissed) {
controller.forward();
}
});
controller.addListener(() {
print(controller.value);
setState(() {});
});
super.initState();
}
@override
Widget build(BuildContext context) {
CurvedAnimation smoothAnimation =
CurvedAnimation(parent: controller, curve: Curves.easeInExpo);
return GestureDetector(
onTap: () {
controller.forward();
},
child: Container(
width: 150,
height: 150,
color: Colors.white,
child: Transform.scale(
scale: Tween(begin: 1.0, end: 1.5).transform(controller.value),
child: Icon(
Icons.favorite,
color:Colors.red,
size: 60,
),
),
),
);
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
void toggleVisible() {
print('Button clicked');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment