0

Currently I am trying to run a project where i am auto generating the response files. But I am getting some error while running build_runner cmd.

Command to auto generate files:

flutter pub run build_runner build

Following is the error that I am getting:

Bad state: Unexpected diagnostics:
/Users/user/development/flutter/bin/cache/dart-sdk/lib/internal/internal.dart:691:16 - This requires the 'non-nullable' language feature to be enabled.
[SEVERE] json_serializable:json_serializable on lib/database/database_helper.dart:

Bad state: Unexpected diagnostics:
/Users/user/development/flutter/bin/cache/dart-sdk/lib/internal/internal.dart:691:16 - This requires the 'non-nullable' language feature to be enabled.
[INFO] 1.7s elapsed, 1/17 actions completed.
[INFO] 2.8s elapsed, 1/17 actions completed.
[INFO] 3.9s elapsed, 1/17 actions completed.
[INFO] 5.0s elapsed, 1/17 actions completed.
[INFO] 6.0s elapsed, 1/17 actions completed.


This remains in infinite loop and never ends.

Following is the Pubspec.yaml file

Why might this be occurring?

Changed the environment to sdk: ">=2.12.0 <3.0.0"

But this is the error that I am getting while running the command:

[SEVERE] Failed to snapshot build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.
[SEVERE] .dart_tool/build/entrypoint/build.dart:27:3: 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 dependenciesdon't support null safety: - package:build_runner_core - package:json_serializable - package:retrofit_generator - package:source_gen - package:build_config - package:build_runner - package:build - package:json_annotation - package:glob - package:crypto - package:logging - package:watcher - package:build_resolvers - package:timing - package:graphs - package:package_config - package:yaml - package:analyzer - package:built_collection - package:code_builder - package:dart_style - package:dio - package:tuple - package:retrofit - package:checked_yaml - package:pubspec_parse - package:build_daemon - package:args - package:io - package:convert - package:pub_semver - package:quiver - 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:fixnumFor solutions, see https://dart.dev/go/unsound-null-safety.dart_tool/build/entrypoint/build.dart:25: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, [_i6.SendPort sendPort]) async {   
halfer
  • 19,824
  • 17
  • 99
  • 186
Sagar Acharya
  • 3,397
  • 4
  • 12
  • 34

4 Answers4

0

I think your problem regards sound null safety.

Try to set your environment for null safety in your pubspec.yaml

environment:
  sdk: ">=2.12.0 <3.0.0"

Then run flutter clean and flutter pub get

Docs here: https://dart.dev/null-safety

Davide Bicego
  • 562
  • 2
  • 6
  • 24
0

if you use version sdk: ">=2.12.0 <3.0.0. all package in your pubspec.yaml migrate it to null-safety version, but if you don't want use null-safety package, you can try flutter run --no-sound-null-safety in your terminal

Anwar
  • 169
  • 3
  • 8
  • Some of my packages do not support null saftey. Due to which the build runner is not generating the files. Cmd you have mentioned will be executed after file generation right? – Sagar Acharya Nov 07 '21 at 15:47
0

This is a 'missing null safety' generated error ,

what is null safety in Dart language ?

answer :

It is a guarantee within an object-oriented programming language that no object references will have null or void values.

When you opt into null safety, types in your code are non-nullable by default, meaning that variables can't contain null unless you say they can.

How do you avoid null safety errors ?

You can do this in two ways:

  • Disable sound null safety using the --no-sound-null-safety flag to the dart or flutter command: $ dart --no-sound-null-safety run $ flutter run --no-sound-null-safety.

  • Alternatively, set the language version in the entrypoint — the file that contains main() function — to 2.9.

Personnal advice : try to migrate to null safety because flutter will support only null safety pulgins and if you still going the old way you will face lots of issues without documentation, so best way is to merge to nullsafety versions here is a link on how to migrate : Migrate to null safety dart.dev

nadir hamidou
  • 423
  • 2
  • 7
  • 18
0

You could try setting your package versions to :any in your pubspec.yaml. Not recommended but should work.

Dolimight
  • 203
  • 1
  • 8