Ubuntu | Flutter Doctor: dart is not in you current flutter SDK - flutter

Warning: `dart` on your path resolves to /usr/lib/dart/bin/dart, which is
not inside your current Flutter SDK checkout at /home/ankit/flutter.
Consider adding /home/ankit/flutter/bin to the front of your path.
This exception started when the flutter was updated. How do I solve this?

The Problem:
This is happening because you have a separate installation of Dart on your system. The Flutter SDK includes and manages it's own dart SDK, but you can use the dart SDK separately.
Why it Matters
Flutter recommends that you use the dart SDK included with Flutter because Flutter manages it - It will automatically use and upgrade supported versions when using the flutter upgrade command on your terminal, and during initial install.
Flutter is noticing that you have a dart SDK install that did not come with the Flutter SDK. It's giving you a warning because of the possible differences in versions (and possibly other configurations) that could prevent an optimal flutter development experience.
System Path
Here's an explanation of path. You will probably need to set your path environment variables to get the whole fix.
This link shows the official Apple guide to working with the terminal environment variables (including path) but a quick google around should help you find any answers you can't find here.
The path resolves from "front" to "back" - meaning that if the executable in question occurs twice, it will grab the first one. Flutter doctor wants you to add the flutter dart path at the front so that subsequent dart calls will resolve to the Flutter Dart SDK.
The High-Level Solution
Unless you're doing dart development outside flutter, you don't need an additional dart SDK. Most of the time the Flutter dart SDK will work for cases besides flutter as well.
I would recommend removing your other dart install, and using the dart install that comes with flutter. This process will vary depending on how you installed the other dart SDK.
TLDR/Quick Fix
based on what you provided, run this on your Zsh command-line:
export PATH="/home/ankit/flutter/bin:$PATH"
It will only work until you restart your computer.

Related

I get this error in my flutter app. migrate this app to the V2 embedding

I get this error in my Flutter Project,
C:\src\flutter\bin\flutter.bat --no-color pub get
Running "flutter pub get" in source_code... 34.3s
This app is using a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to migrate this app to the V2 embedding.
Take a look at the docs for migrating an app: https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects
The plugin firebase_core requires your app to be migrated to the Android embedding v2. Follow the steps on https://flutter.dev/go/android-project-migration and re-run this command.
Process finished with exit code 1
Flutter Embedding Error
Since Flutter 1.12 the way how Flutter plugins communicate with the native Android side has been improved. Allowing plugins to better integrate with the native Android lifecycle.
Some plugins support both the new and the old structure, however many plugins (like firebase_core) dropped support for the legacy structure to ensure optimal integration with the Android system.
Apps created using Flutter 1.12 and higher automatically generate the correct Android integration logic, however Flutter applications created with an earlier version of Flutter need to be manually migrated. There are two options to fix this for your app:
The easiest solution is to delete the android folder in your project and let Flutter (using Flutter 1.12 or higher) recreate it for you by running the following command in the root folder of the Flutter project: flutter create --platform=android . (don't forget the . at the end of the command). You should only do this if you haven't made any custom changes to the Android code and of course make sure to make a backup first.
The more safe option is to manually migrate the Android project using the instructions provided on the GitHub Wiki page mentioned in the error message.
When following the instructions on the GitHub Wiki page make sure to keep an eye on all the details. Personally I forgot to update the <application android:name="MyApp" to the recommended <application android:name="${applicationName}" which resulted in the same error you are reporting.
What helped me was to create a new "dummy" application with the latest version of Flutter (for example flutter create --platforms=android test_app) and compare the files in the Android folder with the files of my current App and make changes where necessary.

VSCode, Flutter SDK Version Erroneous?

I believe my Flutter SDK version is being erroneously reported and do not know where the conflict is.
When running flutter doctor it reports Flutter 2.2.3 • channel stable. However, the bottom toolbar in VSCode displays Flutter: 2.0.4.
Is there a reason VSCode and terminal would report the Flutter version differently? And how can I ensure I am running the correct SDK version?
Look into "dart.flutterSdkPath" setting in vscode and change if needed. The problem could be with you having multiple versions of Flutter on the disk and auto-find fails to find the correct one (last version), manually override.
In my case my path( environment variables) of SDK was set wrong check yours first
and if still not worked try running commands
Flutter clean
Flutter upgrade

Flutter version used in project

Where can I see the flutter version used in a flutter project? Is there a file inside the project directory where I can see it? I think it is not specified inside the pubscpec.yaml file
So far, I think the specific version can not be found but only what versions can be used in a project. It can be found at the bottom part of pubscpec.lock file
pubspec.lock screenshot
It will not show version project wise. It will overall flutter version that you have installed in your system. For that:
Open your flutter project root directory in Command Prompt or Terminal type:
flutter --version command.
After typing the above command hit enter and You’ll see it will display us the currently installed flutter and Dart version in your computer and also tells us which version type we have installed like Stable or Beta.
Note: There is no such feature/command to check about which version of flutter you have used in Specific project.
Check this thread it will give you more idea:
https://github.com/flutter/flutter/issues/14230
All projects you run will use the flutter sdk installed in your machine/computer from where you specified its location from. So if the version the project uses don't match with the version you've and they conflict, you will have errors and if there is a huge gap and breaking changes, you'll need to either upgrade or downgrade the sdk. But most of the time, things are deprecated before they just become breaking changes and so you shouldn't have big issues. So the best thing to do is usually to upgrade. First check your sdk version via flutter --version. If its outdated, use flutter upgrade to upgrade it.
You can either run flutter --version to check flutter version installed on your machine or check it in your pubspec.lock file for current flutter version in your project
sdks:
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.16.0 <2.0.0"

How to use both Flutter stable and dev SDK on the same machine?

I'm working with Flutter to make a Mobile App using the stable Flutter SDK release. But I also want to try Flutter Desktop and Flutter Web that are not part of the Flutter stable channel yet, but are present on the Flutter dev channel.
My question is... How can I try Flutter Desktop and Flutter Web without override the Flutter stable release on my machine?
You'll need to setup alias to switch between different environments easily.
See here a detailed article for that.
I found this Dart package called Flutter Version Management that does exactly what I want.
As the docs says:
Flutter Version Management: A simple cli to manage Flutter SDK versions.
Features:
Configure and use Flutter SDK version per project
Ability to install and cache multiple Flutter SDK Versions
Fast switch between Flutter channels & versions
Dynamic SDK paths for IDE debugging support.
Version FVM config with a project for consistency across teams and CI environments.
Set global Flutter version across projects
https://github.com/leoafarias/fvm
Now I just need to add FVM_HOME/default/bin to the PATH and FVM will take care of everything...
Two solutions
Put the installation files in two different directories one with stable and the other dev and add one of them to the path then you can change the path variable when needed to use the other channel.
Put the flutter repository file in two different directories one with stable and the other with dev then,
add the first installation to the path then add an alias to point to the second installation directory.

How can i 'complete' my dart SDK rather than installing a separate version when using flutter?

I installed flutter by downloading and installing a release version.
It contains a partial dart SDK in its cache subfolder.
Namely, it's missing (amongst others executables) dart2native.
I realize I could just download and install a separate dart SDK from their website, then change all my paths to point to this newer, complete SDK. But that's exactly the problem - I do not wish to run 2 sdk version in parallel, it's confusing and likely will cause errors down the line (for example, my copy of android studio might be pointing at this or that SDK, and god knows what other tools might point towards it).
Question: is there a way to 'fill' my flutter dart SDK with the missing tools? Or am i doomed to run 2 version of dart SDK in parallel?
Answering my own question - after much googling, I found a repo maintainer stating that "For now, if you want to do to Dart development and use the Dart terminal commands (like dartfmt, pub, or dart2native), it's recommended that you download and install the Dart SDK. If you'd like you can also add it to path."
This is clearly sub-optimal. In fact just as I expected it seems to have led to a few people having faced issues, comment on https://github.com/flutter/flutter/issues/43968 if you'd like to see this addressed.