#flutter
Вопрос:
Я анимирую изображение на 360 градусов, я пишу код и инициализирую некоторые свойства Вот код :
import 'package:flutter/material.dart';
import 'dart:math' as math;
class BasicAnimations extends StatefulWidget {
@override
_BasicAnimationsState createState() => _BasicAnimationsState();
}
class _BasicAnimationsState extends State<BasicAnimations>
with SingleTickerProviderStateMixin {
Animation<double> _animation;
AnimationController _animationController;
@override
void initState() {
_animationController = AnimationController(duration: Duration(milliseconds: 1500) ,vsync: this);
_animation = Tween<double>(begin: 0, end: 2 * math.pi).animate(_animationController);
_animationController.forward();
super.initState();
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Basic Animations"),
),
Итак, в body: Transform.rotate я установил _animation.значение, и эта ошибка thorw «значение» была вызвана нулевым кодом :
body: Transform.rotate(
angle: _animation.value,
child: Center(
child: Container(
width: 150,
height: 150,
child: Image.asset("assets/flutter_2.png")),
),
),
);
}
}
Есть какое-нибудь решение для этого ? Заранее спасибо 🙂
Комментарии:
1. Я запускаю ваш код и его работу 🙂
Ответ №1:
Напиши это:
AnimationController _animationController = AnimationController();
Сначала вам нужно создать его AnimationController
экземпляр, а затем вызвать, как вы сделали бы с TextEditingController и другими контроллерами в целом.