尽管变量是在initState中初始化的,但我遇到了"无效的常量值"问题.
你能解释一下为什么会发生这种情况吗?
我已经对代码中的关键点进行了注释.
谢谢.
附言:我用的是Flutter 翼3.16.5和省道3.2.3
class _LoadingScreenState extends State<LoadingScreen>
with TickerProviderStateMixin {
AnimationController? _animationController; // !Declare!
@override
void initState() {
_animationController = AnimationController( // !Initialization in initState!
vsync: this,
);
}
@override
void dispose() {
_animationController?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return const Scaffold(
body: ClipRect(
child: Stack(children: [
WelcomeView(
animationController: _animationController!, // !I got invalid constant value issue here!
),
]),
),
);
}
}