I'm trying to add the curves class animation 'Curves.bounceOut' to my code that uses an AnimationController.
Here is my code:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
var squareScale = 1.0;
static AnimationController _controller;
@override
void initState() {
_controller = AnimationController(
vsync: this,
lowerBound: 0.5,
upperBound: 1.0,
duration: Duration(milliseconds: 300));
_controller.addListener(() {
setState(() {
squareScale = _controller.value;
});
});
super.initState();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Bounce Example"),
),
body: Stack(
children: <Widget>[
Container(
width: 150.0,
height: 150.0,
color: Colors.yellowAccent,
),
Column(
children: <Widget>[
Row(
children: <Widget>[
GestureDetector(
onTap: () {
_controller.forward(from: 0.0);
},
child: Transform.scale(
scale: squareScale,
child: Container(
width: 150.0,
height: 150.0,
color: Colors.green,
),
),
),
],
),
],
),
],
),
);
}
}
Currently the green container animates from 0.5 scale to 1.0 scale but does not bounce. How can I add the 'Curves.bounceOut' animation so the container bounces when tapped?
Thanks in advance for any help!