Reputation: 5545
Getting error in MyApp
constructor
const MyApp({Key? key}) : super(key: key);
This requires the 'non-nullable' language feature to be enabled. Try updating your pubspec.yaml to set the minimum SDK constraint to 2.12.0 or higher, and running 'pub get'.
but sdk is by default set to 2.12.0 already
sdk: ">=2.12.0 <3.0.0"
This project is created with the latest versions of Flutter and Dart.
Dart version: 2.13.3
Flutter version: 2.2.2
Upvotes: 6
Views: 8142
Reputation: 1820
In my case, I had to set it to 2.13.0 to make the error go away:
sdk: ">=2.13.0 <3.0.0"
Upvotes: 4
Reputation: 10136
A few possibilities:
// @dart=2.9
. This will disable null safety for that file. Check for such a comment, and remove to solve the errorlib/main.dart
) has an overridden language level, it will apply that to the project. This error occurs when using flutter run
, but is typically not shown in the IDE during developmentwhich flutter
to see where on your PATH
the executable is. You can then compare this to the version your IDE uses (varies by IDE)Upvotes: 2
Reputation: 313
it is because of your IDE is using older version of flutter so try to upgrade flutter using this command in your terminal
flutter upgrade
if stills problem occurs try to clean the project by using command in terminal
flutter clean
if you want to check whether the flutter is installed properly or not you can check this by writing command in your terminal
flutter doctor
Upvotes: 1