Although a variable is initialized in initState, I encountered the 'Invalid constant value' problem.
Could you please explain why this occurs?
I've annotated key points in the code.
Thank you.
P.S: I'm using Flutter 3.16.5 and Dart 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!
),
]),
),
);
}
}
Remove the const
keyword before the Scaffold
widget.
@override
Widget build(BuildContext context) {
return Scaffold(
}