9

I want to use the NNBD Dart feature in my Flutter app today, but I could not find out how to use it.

If I try to use int? et al., I get the following error:

This requires the 'non-nullable' experiment to be enabled.
creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402

2 Answers2

21

With Flutter 2

As of Flutter 2 (and Dart 2.12), null safety is the new default. This means that by specifying the following SDK constraint:

environment:
  sdk: '>=2.12.0 <3.0.0'

You automatically opt into null safety.

Pre Flutter 2

You need to make sure that your Dart SDK version constraint is 2.9.0 in your pubspec.yaml file (use flutter channel master):

environment:
  sdk: ">=2.9.0-8.0 <3.0.0"

Now, you can add an analysis_options.yaml file next to your pubspec.yaml file:

analyzer:
  enable-experiment:
    - non-nullable

You should not expect compilation to succeed as of now.

creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402
2

change sdk version on given below

 environment:
      sdk: ">=2.12.0 <3.0.0"

then, run flutter pub get