Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

'Invalid constant value error' of Flutter

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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! 
          ),
        ]),
      ),
    );
  }
}

>Solution :

Remove the const keyword before the Scaffold widget.

@override
  Widget build(BuildContext context) {
    return Scaffold(
       
  }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading