Dart get won't run - flutter

I am facing a problem that really isn't making any sense, a problem that started when I wanted to use the "http" and "provide" dependencies by entering them into the pubspec.yaml file.
pub get won't run due to the dart version being lower than 2.16.1 even though when I run dart --version it informs me that I do have the latest dart version (2.16.1).
I tried finding answers on the internet including on the https://dart.dev/ site. I really don't know what else to do at this point, as this is for my assignment due on the 25th of March 2022. please help.

In your pubspec.yaml, just above where your screenshot cuts off, there is a line that looks like this.
environment:
sdk: ">=2.14.0 <3.0.0"
Update this to the following:
environment:
sdk: ">=2.16.1 <3.0.0"
You updated Dart on your local machine, but you never updated your project to reflect that it should use this version (or a higher version).

Related

Migrating to Flutter 2 fail

I have a project that is developed with Flutter v1.22.6 and was working great, after updating the flutter to v2.0.0 and reading the documentation, I've found out I can use dart migrate --apply-changes to fix issues that are related to flutter upgrade, By running the command I get dozens of errors and the error ends with:
The migration tool didn't start, due to analysis errors.
The following steps might fix your problem:
1. Set the lower SDK constraint (in pubspec.yaml) to a version before 2.12.
2. Run `dart pub get`.
3. Try running `dart migrate` again.
What is the simplest way to migrate the current project to the v2?
The problem is that you have already migrated to a newer version of dart.
You can't migrate your projects from the new version, there is literally nothing to migrate to.
If you want to migrate your older projects (which are without null safety) to a new version, your dart version must be older than 2.12.0 version.
In this case, consider changing the version in your pubspec.yaml file.
environment:
sdk: '>=2.11.0 <3.0.0'
Then run the command in your terminal
> dart migrate --apply-changes
make sure you have following step by step migrate dart 2
and base on your error notification try to set in pubspec.yaml
environment:
# Works in Dart 2 only.
sdk: '>=2.0.0 <3.0.0'

Using Futures in flutter old versions

Android studio is giving me this error
info: The class 'Future' wasn't exported from 'dart:core' until version 2.1, but this code is required to be able to run on earlier versions.
If I put this
import 'dart:async';
the problem seems to go away. Could someone explain why this is happening and if this is the correct way to fix this.
Thanks a lot.
---- edit
Can I update dart core to something > 2.1
I am guess it is this line in my pubspec yaml
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
Is there any downsides to doing thins i.e. running on older android/ios versions.
Open the terminal and execute the following:
flutter upgrade
This will upgrade both flutter and dart

Dart 2.6 and Flutter, Upgrading Dependency

Using Flutter, I am trying to update my dart dependency 2.6.0 but I get an error
Because *project_name* requires SDK version >=2.6.0 <3.0.0, version solving failed.
pub get failed (1)
exit code 1
I want to use the new features that dart offers, such as Extension Methods. How could I go about upgrading my dependency? I have installed the newest stable version of dart on my computer, but regardless I still get that error.
A couple of things that might help:
From this issue, you can try ensuring that you've updated enviroment in your pubspec.yaml file like so:
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
Another thing that might help is just double checking the steps in this post or on the dart installation page to ensure that you've updated to the latest version correctly.

Error: This requires the 'non-nullable' experiment to be enabled

I am playing around with non-nullable types and added this to my analysis_options.yaml:
analyzer:
enable-experiment:
- non-nullable
I have a code-generator that is utilising the nullability extension. Visual Code is fine with my code.
Now, I try to run:
flutter packages pub run build_runner watch
I get this error message:
[SEVERE] Failed to snapshot build script .dart_tool/build/entrypoint/build.dart.
This is likely caused by a misconfigured builder definition.
[SEVERE] xyz.dart:95:7: Error: This requires the 'non-nullable' experiment to be enabled.Try enabling this experiment by adding it to the command line when compiling and running.
How can I pass --enable-experiment:non-nullable to flutter packages pub run?
The same happens if I run:
flutter build ios
I get the error message:
lib/main.dart:61:26: Error: This requires the 'non-nullable' experiment to be enabled.
Try enabling this experiment by adding it to the command line when compiling and running.
So, same question: How can I pass --enable-experiment:non-nullable to flutter build?
This problem was occured for me after upgrading the Flutter.
I solved it by cleaning and upgrading the project dependencies again.
Run the below commands in the root directory of your project:
flutter clean
flutter packages pub upgrade
flutter pub run build_runner build
Also as others said, please make sure your sdk version in the pubspec.yaml is compatible with your flutter sdk version.
For null safety to work,
environment:
sdk: ">=2.12.0 <3.0.0"
should be this version at least.
then run flutter clean
and flutter pub get it will work.
Try
flutter clean
This is worked for me!
Depending on what you're doing, sometimes it's as simple as changing the environment in your pubspec.yaml file to update the lower end, ie change a lower end like
environment:
sdk: ">=2.0.0 <3.0.0"
to
environment:
sdk: ">=2.6.0 <3.0.0"
or
environment:
sdk: ">=2.7.0 <3.0.0"
This has worked for the various things that cause this error (using spread syntax in latest version of flutter and dart will also cause this), but I don't need the older environments.
A simple fix for me was to ensure that the analysis_options.yaml is in
the root folder. In my case, it was in the lib folder and none of the
experimental features worked until I moved the file to the same folder
as pubspec.yaml. Other things that can happen include updates that
make the experimental feature no longer required so updating to the
latest version on the flutter master channel may be useful in addition
to verifying the file location. Haven't been able to get the command line
running with this option, however.
Dart Reference
Example of Analysis Options File

Because every version of flutter_test from sdk depends on... flutter_test from sdk is forbidden, version solving failed

I'm having this issue when I've added http dependency in my flutter project. Can anyone please help me with it?
If you get the message:
Because every version of flutter_test from sdk depends on...
It means flutter_test depends on a dependency with version lower than you specified in another dependency.
To solve this, open pubspec.yaml, and remove the version number of the problem dependency:
Example:
Change
archive: ^2.0.13 --> remove this number
To:
archive:
You have provided or trying to use http: ^0.12.0 dependency on implementing API calls in pubspec.yaml file but flutter_test will require http: ^0.11.3+17. That's why it fails. Please replace
dependencies:
flutter:
sdk: flutter
http: ^0.12.0
with
dependencies:
flutter:
sdk: flutter
http: ^0.11.3
Hope it will help you out.
In my case, I somehow deleted sdk: flutter:
dependencies:
flutter:
sdk: flutter
I was facing a similar error. I solved it by removing all the version numbers from the dependencies: section in pubspec.yaml.
So, if my pubspec.yaml looked like this before:
dependencies:
freezed_annotation: ^0.14.3
I changed it to this:
dependencies:
freezed_annotation:
I'm assuming this fetches the latest "possible" version of each package.
Can you please provide the dependencies in your pubspec.yaml? It looks like your app depends on at least http 0.12.0 but flutter_test specifically requires http 0.11.3+17 (an older version) which makes it fail.
If your app doesn't have too many dependencies that could broke, you can try to upgrade your Flutter version: flutter upgrade.
It most probably will fix this problem. But always be sure to understand that your app might break at unexpected places.
So you're fine if:
either you're doing it for small app
or it's big app at work and it has extensive tests that will tell you something has broken
if big app without tests, be sure to test every important place of the app, where dependencies are being used
Try to change the dependency version that you were added in your pubspec.yaml file
don't use the current or latest version try some previous versions of dependency.
for ex - if you are using latest sqflite version then chnage to previous version of that and then re-run your whole project.
In my case IDE referred to an an older version of dart because of fvm. Seems like 'run' button called fvm flutter run, but not flutter run as I expected. After I deleted fvm folder from the project the problem has gone.
Change depending attributes version inside pubspec.yaml
if it says depands on http *** than change http version
or if it says depands on collection *** than change collection version.