Flutter clean command causes null safety errors - flutter

Ever since null-safety was introduced to Flutter, when I do flutter clean, the whole project switches to null-safety.
I can not update my whole project to null-safety quite yet as many packages I use have not migrated.
How can I do a flutter clean without getting thousands of errors telling me that non-nullable item must be initialized first...
I am currently on Flutter 1.24.0-10.2-pre, channel beta.
pubspec.yaml includes the following
environment:
sdk: ">=2.2.2 <3.0.0"

I get exactly the same issue. I haven't found a fix yet but if you open the pub spec.yaml file and save it without making changes it solves the issue until you next run flutter clean.

I have the same issue. For me running flutter pub get worked. But I still don't know why this error happens

Using VS code editor:
Go to terminal
Execute flutter pub get
The above fixed similar issue I got

I have the same problem, For me
Go To 'Terminal'
Type 'flutter pub get'
That is!!
I am using VS code.

Sometimes you have to run this command:
dart pub upgrade
or
dart pub update

If you get an error after running "flutter clean", do the following to solve the problem;
Go to your terminal
Run this command: "flutter pub get"
After this you'll see "Running 'flutter pub get' in 'xxx'(where xxx stands for the name of your project)
When this is complete, all will be reset back to normal

Related

Build failed with an exception

while running the code got this error. I tried to reinstall the flutter ,but did not work
It looks more like a Java error,
Just to have a clear conscience, i would suggest you to run the very classic
flutter clean
and then
flutter pub get
if you're using build_runner in your project, run:
flutter pub run build_runner build --delete-conflicting-outputs
Restart your computer, it worked for some people with the same problem (Linked at the end).
If nothing of this works, reinstall your Java.
Check this for more info:
Cannot create service of type TaskExecuter using ProjectExecutionServices
https://github.com/gradle/gradle/issues/12436#issuecomment-678389275

Error: Target of URI doesn't exist: 'package:flutter/material.dart'. (uri_does_not_exist at [myapp] test/widget_test.dart:8)

I made an app in Flutter and there are no errors on its Dart file but I suddenly end up with errors on widget_test.dart. can you guys help me out. Thanks
Run flutter clean, and then flutter pub get in the terminal respectively.
If that doesn't work, try running flutter upgrade, and then repeating the initial steps.
Finally, if it still isn't working, you can run flutter doctor to see if there's anything glaringly wrong with your project.

Issue with Pub Get via dart extension in VSCode

I've got a problem where running pub get via the VSCode dart extension doesn't actually get the packages. It doesn't return an error but if I attempt to build my project, it will just continuously tell me my pubspec lock has updated since I last ran pub get.
Running flutter pub get via terminal solves the issue straight way.
Has anyone else experienced this with VSCode?
You can
delete pubspec.lock
then
flutter clean
Reinstall Extensions

'flutter pub get' does not work in VSCode

I'm currently developing flutter application with VSCode and want to add some packages. ex) dropdown_menu
I did flutter pub get / flutter packages get / clicking down arrow button in vscode(get Packages)
and this is all I get everytime
PS D:\VSCodeProjects\testt> flutter pub get
Running "flutter pub get" in testt... 0.4s
PS D:\VSCodeProjects\testt>
this is my code in pubspec.
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
dropdown_menu: ^1.1.0
I did turn on / off program( and computer) , restart,
and
flutter clean
flutter packages get
flutter packages upgrade
Does anybody know how to solve??
It's running, by default in vs code whenever you save your .yaml file it runs it under the hood. When you explicitly run it using the command, it takes very less time as the packages are already up to date.
If in doubt, try to use the new packages that you added and they should not give errors.
flutter pub get is meant to be quick especially when you don't have much libraries.
What you see is right there should not be any problem.
But if there is issues where you are going for a specific version and it is not working, this is because pubspec.yaml stores the settings of what version of library but pubspec.lock stores the actual version your app is using.
Judging from your comments of it not showing up. It might be related to this #31115
try the solution and see if it works.
Select the View > Command Palette menubar option
Type "flutter"
Click "flutter get packages"
you can use this in vscode
Pubspec Assist
After typing the package don't forget to save the yaml file or click ctrl + s.

The pubspec.lock file has changed since the .dart_tool/package_config.json file was generated

I'm running a dart only test in intellij and receiving the following error:
The pubspec.lock file has changed since the .dart_tool/package_config.json file was generated, please run "pub get" again.
I have tried pub get a number of times. Any ideas? I'm on the dev branch of Flutter (anything using Dart 2.7 pretty much fails with the same or a similar error message).
Edit
I think that if you have a path reference dependency in the pubspec.yaml file it will fail.
Anything like the following fails with the above message if you try to run a dart test in IntelliJ.
dependencies:
test_dependency:
path: ../test_dependency
I'm not suggesting this is a fix for everyone, but it did resolve my particular situation.
Just ran into this error after upgrading flutter from 1.22.6 to 2.0.2 and trying to use build_runner: ^1.12.2 and json_serializable: ^4.1.0 to generate json serialization/deserialization classes & methods.
The problem is apparently related to the pub package when used with relative paths for packages as noted in the following github issues:
https://github.com/dart-lang/pub/issues/2806
https://github.com/dart-lang/pub/pull/2830
One of the commenters in issue 2806 mentioned running flutter create . inside the flutter project folder which rebuilds .dart_tool/package_config.json, adding any missing entries, solving the problem.
No one solved this problem so far?
I've found a staightforward solution and it works fine for me.
You need to close your IDE (VSCode in my case), make sure that is completely closed using process-monitor.
Then open a terminal window manualy in your project folder and run "flutter pub get"
After that just start your IDE normaly and ewerything will work fine.