Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Created October 23, 2019 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/fbbbf5c55f2d5c173c3cbaf12aca7142 to your computer and use it in GitHub Desktop.
Save McLarenCollege/fbbbf5c55f2d5c173c3cbaf12aca7142 to your computer and use it in GitHub Desktop.
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