12

I have added // @dart=2.9 to all my files but the build_runner won't do its thing without throwing this error:

Warning: Operand of null-aware operation '?.' has type 'SendPort' which excludes null. - 'SendPort' is from 'dart:isolate'.  sendPort?.send(result);  ^Error: Cannot run with sound null safety, because the following dependencies don't support null safety: 
- package:build_runner_core 
- package:json_serializable 
- package:moor_generator 
- package:objectbox_generator 
- package:retrofit_generator 
- package:source_gen 
- package:build_config 
- package:build_runner 
- package:build 
- package:json_annotation 
- package:glob 
- package:pool 
- package:crypto 
- package:logging 
- package:watcher 
- package:build_resolvers 
- package:timing 
- package:graphs 
- package:package_config 
- package:yaml 
- package:analyzer 
- package:sqlparser 
- package:objectbox 
- package:dart_style 
- package:built_collection 
- package:code_builder 
- package:dio 
- package:tuple 
- package:retrofit 
- package:pedantic 
- package:checked_yaml 
- package:pubspec_parse 
- package:build_daemon 
- package:args 
- package:io 
- package:convert 
- package:pub_semver 
- package:ffi 
- package:quiver 
- package:moor 
- package:recase 
- package:_fe_analyzer_shared 
- package:built_value 
- package:http_parser 
- package:http_multi_server 
- package:shelf 
- package:stream_transform 
- package:mime 
- package:shelf_web_socket 
- package:web_socket_channel 
- package:cli_util 
- package:fixnum 
- package:synchronizedFor solutions, see https://dart.dev/go/unsound-null-safety.dart_tool/build/entrypoint/build.dart:44:44: Error: The parameter 'sendPort' can't have a value of 'null' because of its type 'SendPort', but the implicit default value is 'null'. - 'SendPort' is from 'dart:isolate'.Try adding either an explicit non-'null' default value or the 'required' modifier.void main(List<String> args, [_i8.SendPort sendPort]) async { 
nnamdi
  • 131
  • 1
  • 6
  • Did you update all the package's version number to the null-safety version? Since not all of them might support null-safety, you'll have to go with the hybrid solution which is allows both null-safe/ non-null-safe I think. – Bach Apr 05 '21 at 03:48
  • Check this official guide out as well: https://dart.dev/null-safety/unsound-null-safety – Bach Apr 05 '21 at 04:41

3 Answers3

2

Please make sure all of your packages are updated to their respective null-safety version. For build runner use ^1.12.2 and then run below commands in your terminal while sitting in the present working directory.

flutter clean
flutter pub cache repair
flutter pub run build_runner clean
flutter pub get

After then run the build runner command.

This worked for me and I've successfully generated the files using the build runner.

  • 1
    while this is sound advice it hasn't fixed the issue for me, i did delete the .pub-cache folder which worked once but i think this is the equivalent of flutter pub cache repair – martinseal1987 Apr 16 '21 at 09:58
  • 1
    there is an open issue for this here https://github.com/dart-lang/build/issues/3046 – martinseal1987 Apr 16 '21 at 10:02
  • Maybe you're right but the above commands did worked for me. Basically the `cache repair` command performs a clean reinstall of all hosted and git packages in the system cache. https://dart.dev/tools/pub/cmd/pub-cache – Muhammad Salman Siddiqi Apr 16 '21 at 13:14
1

Delete the .pub-cache folder inside your flutter folder and then run pub upgrade, after that you should be able to run:

flutter packages pub run build_runner build --delete-conflicting-outputs
martinseal1987
  • 1,862
  • 8
  • 44
  • 77
0

For those who are you using full sound null-safety i.e. who are not using @dart=2.9 or other means to ignore null-safety.

In your pubspec.yaml file, the lower SDK version should be >=2.12.

environment:
  sdk: '>=2.12.0 <3.0.0'

Use the following versions (all are null-safe)

json_annotation: ^4.0.1
json_serializable: ^4.1.2
build_runner: ^2.0.3
iDecode
  • 22,623
  • 19
  • 99
  • 186