Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
535 views
in Technique[技术] by (71.8m points)

flutter - Error: This requires the 'non-nullable' experiment to be enabled

I am playing around with non-nullable types and added this to my analysis_options.yaml:

analyzer:
  enable-experiment:
    - non-nullable

I have a code-generator that is utilising the nullability extension. Visual Code is fine with my code.

Now, I try to run:

flutter packages pub run build_runner watch 

I get this error message:

[SEVERE] Failed to snapshot build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.
[SEVERE] xyz.dart:95:7: Error: This requires the 'non-nullable' experiment to be enabled.Try enabling this experiment by adding it to the command line when compiling and running.

How can I pass --enable-experiment:non-nullable to flutter packages pub run?

The same happens if I run:

flutter build ios

I get the error message:

  lib/main.dart:61:26: Error: This requires the 'non-nullable' experiment to be enabled.

    Try enabling this experiment by adding it to the command line when compiling and running.

So, same question: How can I pass --enable-experiment:non-nullable to flutter build?

question from:https://stackoverflow.com/questions/57934341/error-this-requires-the-non-nullable-experiment-to-be-enabled

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This problem was occured for me after upgrading the Flutter.
I solved it by cleaning and upgrading the project dependencies again.
Run the below commands in the root directory of your project:

flutter clean
flutter packages pub upgrade
flutter pub run build_runner build

Also as others said, please make sure your sdk version in the pubspec.yaml is compatible with your flutter sdk version.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...