Unable to use spread collections - flutter

On using “...” error is shown that this requires the - -spread-collections experiment to be enabled.
Try enabling this experiment by adding it to the command line when compiling and running. error shown
edit: i upgraded with the latest version of flutter but this error is shown
Even I tried adding enable-experiment: -spread-collections in pubspec.yaml file but didn't work

Set the environment in your pubspec.yaml with
environment:
sdk: ">=2.6.0 <3.0.0"

Related

Bitrise flutter build keeps using older versions of flutter/dart

I have a flutter app that I am trying to build through bitrise.
I keep getting a tonne of errors along the lines of
Error: The 'super-parameters' language feature is disabled for this library.
Try removing the package language version or setting the language version to 2.17 or higher.
super.key
and it is blocking me from analyzing and building the app.
Now the issue is, I am using flutter install with upgrade set to true , and have sdk target in my pubspec.yaml as
Environment:
sdk: ">=2.17.6 <3.0.0"
I disabled the caching steps, and tried to create a new deployment pipeline, to no avail.
In your workflow, add Flutter Install, Then set your desired flutter version on Input Variables sections's Flutter SDK git repository version field. e.g. 2.8.0.

Dart get won't run

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).

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

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