If you want to create AnimationController in the StatelessWidget you must pass TickerProviderStateMixin in the Constructor of your StatelessWidget, look at my sample code :
import 'package:flutter/material.dart';
main() {
runApp(TestyApp());
}
class TestyApp extends StatefulWidget {
@override
_TestyAppState createState() => _TestyAppState();
}
class _TestyAppState extends State<TestyApp> with TickerProviderStateMixin {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: TestAnimationInStatelessWidget(
tickerProviderStateMixin: this,
),
);
}
}
class TestAnimationInStatelessWidget extends StatelessWidget {
final TickerProviderStateMixin tickerProviderStateMixin;
const TestAnimationInStatelessWidget(
{Key key, @required this.tickerProviderStateMixin})
: assert(tickerProviderStateMixin != null),
super(key: key);
@override
Widget build(BuildContext context) {
var _animationController = AnimationController(
vsync: tickerProviderStateMixin, duration: Duration(seconds: 1));
var _animation = Tween<double>(begin: 0, end: 2).animate(CurvedAnimation(
parent: _animationController, curve: Curves.easeInOut));
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
RotationTransition(
turns: _animation,
child: Container(
width: 200,
height: 200,
decoration: BoxDecoration(
color: Colors.blueGrey,
borderRadius: BorderRadius.all(Radius.circular(15)),
),
),
),
SizedBox(
height: 30,
),
RaisedButton(
onPressed: () {
_animationController.reset();
_animationController.forward();
},
child: Text("Start Animation"),
)
],
),
),
);
}
}