Sdk: Strange analyzer error : "Invalid constant value" when I use const Text('foo') in Flutter

Created on 28 Apr 2017  Â·  8Comments  Â·  Source: dart-lang/sdk

I noticed that when I open a Flutter file containing const Text('foo') , everything works, I can compile and launch the app, but the dart analysis show me a "invalid constant value" .

const_error_demo_dart_-_yx017-protos_-____projects_ytbx017_protos__et_2017-04-16-flutter-dragdrop-p1_md_-_rx_3w_-____projects_rx-web_

example gist

if I replace the const Text by a new Text, the error disappears.

I'm using IntelliJ version 2017.1

here my Flutter doctor diagnostic

[✓] Flutter (on Mac OS X 10.12.4 16E195, channel master)
    • Flutter at /Users/rxlabz/dev/tools/flutter
    • Framework revision ffdca6f7e8 (14 hours ago), 2017-04-27 13:12:59 -0700
    • Engine revision 3211d2fca2
    • Tools Dart version 1.23.0-dev.11.11

[✓] Host Executable Compatibility
    • Downloaded executables execute on host

[✓] Android toolchain - develop for Android devices (Android SDK 25.0.2)
    • Android SDK at /Users/rxlabz/Library/Android/sdk
    • Platform android-25, build-tools 25.0.2
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version: OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[✓] iOS toolchain - develop for iOS devices (Xcode 8.3.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 8.3.2, Build version 8E2002
    • ios-deploy 1.9.1
    • CocoaPods version 1.2.0

[✓] Android Studio (version 2.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Gradle version 3.2
    • Java version: OpenJDK Runtime Environment (build 1.8.0_112-release-b06)

[✓] IntelliJ IDEA Ultimate Edition (version 2016.3.6)
    • Dart plugin version 163.13137
    • Flutter plugin version 12.0

[✓] IntelliJ IDEA Ultimate Edition (version 2017.1)
    • Dart plugin version 171.4006
    • Flutter plugin version 13.0

[-] WebStorm (version 2017.1)
    • Flutter plugin not installed; this adds Flutter specific functionality.
    • For information about managing plugins, see
      https://www.jetbrains.com/help/idea/managing-plugins.html

[✓] Connected devices
    • A3 A40 • 622004271815 • android-arm • Android 6.0 (API 23)
P2 area-analyzer closed-obsolete customer-flutter type-bug

All 8 comments

Do you think this is a dup of one of the other recent issues, @scheglov?

Looks somewhat similar to #28775

Open your .analysis_options or analysis_options.yaml file and ensure that there is the following line in it. Also try updating to 1.24 version of SDK.

analyzer:
  language:
    enableAssertInitializer: true

@kasperl Yes, I think this is a dup of other asserts in initializer issues.

I added the analysis.yaml file (I'm not sure if there is not a special way to configure analysis_options for flutter @sethladd ?), restarted the analysis server, but still have the error. My local Dart SDK is updated to 1.24, but I think Flutter is using its own ?

Just to be clear, the name of the analysis options file you added is analysis_options.yaml, correct?

Yes, Flutter bundles a version of the Dart SDK.

yes, sorry analysis_options.yaml. not sure if it can help but here are complete project sources : https://github.com/rxlabz/invalid_const_demo

I don't know if it's after upgrading Flutter yesterday, but my "invalid constant value" error seems to be fixed 🤔

Was this page helpful?
0 / 5 - 0 ratings