I have an error in the code because of safety in Flutter and I have tried to solve it with the declaration of variables using LATE.<br /
But it appears antother one when I try to build it:
This is my code:
class AnimacionesPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: CuadradoAnimado(),
),
);
}
}
class CuadradoAnimado extends StatefulWidget {
@override
_CuadradoAnimadoState createState() => _CuadradoAnimadoState();
}
class _CuadradoAnimadoState extends State<CuadradoAnimado>
with SingleTickerProviderStateMixin {
late AnimationController controller;
late Animation<double> rotacion;
@override
void initState() {
controller = new AnimationController(
vsync: this, duration: Duration(milliseconds: 4000));
rotacion = Tween(begin: 0.0, end: 2 * Math.pi)
.animate(CurvedAnimation(parent: controller, curve: Curves.easeOut));
@override
Widget build(BuildContext context) {
// Play / Reproducción
controller.forward();
return AnimatedBuilder(
animation: controller,
child: _Rectangulo(),
try this
class _CuadradoAnimadoState extends State<CuadradoAnimado>
with SingleTickerProviderStateMixin {
AnimationController? controller;
Animation<double>? rotacion;
@override
void initState() {
controller = new AnimationController(
vsync: this, duration: Duration(milliseconds: 4000));
rotacion = Tween(begin: 0.0, end: 2 * Math.pi)
.animate(CurvedAnimation(parent: controller, curve: Curves.easeOut));
controller.forward();
setState((){});
}
@override
Widget build(BuildContext context) {
// Play / Reproducción
return controller==null && rotacion==null ? CircularProgressIndicator.adaptive(): AnimatedBuilder(
animation: controller!,
child: _Rectangulo());