1

I've activated Dart non-nullable syntax experiment in my pubspec.yaml file:

name: tests
description: A new Flutter application.

publish_to: 'none'
version: 1.0.0+1

environment:
  sdk: ">=2.9.0-21.0.dev.flutter <3.0.0"

analyzer:
  enable-experiment:
    - non-nullable

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^0.1.3

dev_dependencies:
  flutter_test:
    sdk: flutter
flutter:
  uses-material-design: true

So, now after running flutter pub get I'm trying to create a class using non-nullable syntax:

class Component_Decorator_A extends Component_Decorator {
  Component_Decorator_A([Component? component]) : super(component);

  @override
  operation() {
    component?.operation();
    print('Component_Decorator_A.Operation()');
  }
}

Quite surprisingly, syntax analyzer in Android Studio says:

This requires non-nullable language feature to be enabled. Try updating your pubspec.yaml to set the minimum SDK constraint to 2.9.9 or higher, and running pub get.

Ok, I cannot set the minimum SDK version to exactly 2.9.0 as suggested, as far as each time I try to set environment: sdk: ">=2.9.0 <3.0.0" in my pubspec.yaml, the subsequent flutter pub get leads to the next version solving error that I was unable to resolve:

flutter pub get
Running "flutter pub get" in master000... 

The current Dart SDK version is 2.9.0-21.0.dev.flutter-2e05e6c94a.

Because patterns_experiments_and_tests requires SDK version >=2.9.0 <3.0.0, version solving failed.
---- Log transcript ----
FINE: Pub 2.9.0-21.0.dev.flutter-2e05e6c94a
MSG : Resolving dependencies...
SLVR: fact: patterns_experiments_and_tests is 1.0.0+1
SLVR: derived: patterns_experiments_and_tests
SLVR: fact: patterns_experiments_and_tests requires SDK version >=2.9.0 <3.0.0
SLVR: conflict: patterns_experiments_and_tests requires SDK version >=2.9.0 <3.0.0
SLVR: Version solving took 0:00:00.060030 seconds.
    | Tried 1 solutions.
FINE: Resolving dependencies finished (0.1s).
ERR : The current Dart SDK version is 2.9.0-21.0.dev.flutter-2e05e6c94a.
    | 
    | Because patterns_experiments_and_tests requires SDK version >=2.9.0 <3.0.0, version solving failed.
FINE: Exception type: SolveFailure
FINE: package:pub/src/solver/version_solver.dart 312:5   VersionSolver._resolveConflict
    | package:pub/src/solver/version_solver.dart 133:27  VersionSolver._propagate
    | package:pub/src/solver/version_solver.dart 97:11   VersionSolver.solve.<fn>
    | ===== asynchronous gap ===========================
    | dart:async                                         Future.catchError
    | package:pub/src/utils.dart 113:52                  captureErrors.wrappedCallback
    | package:stack_trace                                Chain.capture
    | package:pub/src/utils.dart 126:11                  captureErrors
    | package:pub/src/command_runner.dart 193:13         PubCommandRunner.runCommand
---- End log transcript ----

pub get failed (1; ---- End log transcript ----)
Process finished with exit code 1

It should be noted here that flutter doctor -v reports that everything is pretty 'OK' in the project:

[✓] Flutter (Channel master, 1.21.0-5.0.pre, on Mac OS X 10.15.5 19F101, locale ru-RU)
    • Flutter version 1.21.0-5.0.pre at /Applications/flutter
    • Framework revision 2a063fc6c0 (11 дней назад), 2020-07-17 12:51:01 -0400
    • Engine revision 1493883bf0
    • Dart version 2.9.0 (build 2.9.0-21.0.dev 2e05e6c94a)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
    • Android SDK at /Users/sergeglushenko/Library/Android/sdk
    • Platform android-30, build-tools 30.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.5)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.5, Build version 11E608c
    • CocoaPods version 1.8.4

[✓] Android Studio (version 4.0)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 47.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (1 available)
    • macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.5 19F101

Would you please suggest me what should be done to make Dart non-nullable syntax steadily usable in Android Studio (latest version)?

julemand101
  • 28,470
  • 5
  • 52
  • 48

1 Answers1

0

I think this issue was being resolved with the new version. The migration guide for null safety is out now a mentioned in this comment:

Please read https://dart.dev/null-safety/migration-guide. You can't just turn on null safety. We have docs and migration tooling available for you!

And if it still doesn't work, try the suggestion here:

You should increase your current sdk version from sdk: ">=2.7.0 <3.0.0" to sdk: ">=2.12.0 <3.0.0" and run flutter pub get. If you don't want to do that manually, you should run dart migrate --apply-changes in terminal. I recommend the second one

MαπμQμαπkγVπ.0
  • 5,887
  • 1
  • 27
  • 65