This is the error:
Bad state: Unexpected diagnostics:
C:\flutter\bin\cache\dart-sdk\lib\internal\internal.dart:172:16 - This requires the 'non-nullable'
language feature to be enabled.
[SEVERE] json_serializable:json_serializable on test/widget_test.dart:
This just happened after the last flutter upgrade. I've tried many solutions but nothing worked, even i reinstalled the flutter SDK.
This is the pubspec.yaml
:
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
json_annotation: ^3.0.1
cupertino_icons: ^0.1.3
dev_dependencies:
flutter_test:
sdk: flutter
build_runner:
json_serializable: ^3.3.0
The test code:
import 'package:json_annotation/json_annotation.dart';
part 'test.g.dart';
//@JsonSerializable(nullable: true)
//@JsonSerializable(nullable: false)
@JsonSerializable()
class Test{
final String test;
Test(this.test);
}
From the terminal: Run flutter pub get . From Android Studio/IntelliJ: Click Packages get in the action ribbon at the top of pubspec. yaml . From VS Code: Click Get Packages located in right side of the action ribbon at the top of pubspec.
simplest way to solve this
like this
environment:
sdk: ">=2.1.0 <3.0.0"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With