Flutter-Dart language SDK environment configuration and error resolution

Flutter's Dart language


Mac VSCode When configuring Dart to
 
learn Dart, use VSCode as an editor. 

On the one hand, it is very convenient to write code, and I also like the interface style. 
On the other hand, I can quickly see the effect of my code on the terminal. 
Writing Dart using VSCode requires Dart to be installed. Plug-ins: 

Dart and Flutter plugins are for 
Code Runner development for Flutter development. Click the button in the upper right corner to let me run the code quickly

 

 

Hello World


Create a new helloWorld.dart file in VSCode and add the following content


main (List <String> args) { print ( ' hello world dart ' ); }

run code or the run button in the upper right corner (when you install the Code Runner plugin) Yes )

Error:
Dart_LoadScriptFromKernel: The binary program does not contain 'main'.

Solution:
  Save the (command + s) code first, and then run it.

 

tips: problems encountered

To develop projects with flutter, the flutter environment is configured. Need to learn dart language, output error when running dart with VSCode: 

bin / sh: dart: command not found
Reason: 

If you are only developing a mobile project, you do not need to install the dart SDK separately, and configure the environment variables of dart. The dart SDK is included in the flutter SDK. But if you want to learn dart language and run dart code with VS Code, you need to configure the installation path of dart SDK in the environment variables. Otherwise, the following error will be reported and the dart command cannot be found. If you want to develop Dart Web, libraries and command-line tools required for command-line and server applications, you need to install the dart SDK without developing mobile applications without configuring the flutter environment.
Solution: 

Configure the installation path of dart SDk to environment variables. 

You can open the .bash_profile file through the editor through the terminal or display hidden files.
1. First find the dart SDK installation path, directly drag the bin directory under dart-sdk to the terminal, and the path will be displayed.
2. Set the environment variable 

Open the environment variable through the terminal . Bash_profile file 
sudo vi ~ /. Bash_profile 

(vim use mode to open the file, input method English status edit file input i, exit esc key: wq)
Configure the dart SDK installation path: 

#Dart environment variable 
export DART_HOME = This is the dart SDK path all the way to the bin directory. Below is my full path 
export DART_HOME = / Users / wrp / flutter / bin / cache / dart-sdk / bin 
export PATH = " $ {DART_HOME}: $ {PATH} " 

There are several ways to set the path. 
Export PATH = $ {PATH}: dart SDK path 

export PATH = dart SDK path: $ {PATH}

3. Save the configuration after the environment is configured: 

source ~ / .bash_profile
4. Type in the terminal:
dart 
prints:

  Usage: dart [<vm-flags>] <dart-script-file> [<script-arguments>]

  Executes the Dart script <dart-script-file> with the given list of <script-arguments>.

dart - version 
print:
  Dart VM version:
2.8 . 0 -dev. 20.0 .flutter-1210d27678 (be) (Mon Apr 6 10 : 36 : 50 2020 + 0000 ) on " macos_x64 " means Dart environment configuration is successful, then Restart VSCode

 
Note: To write dart code using VSCode, you need to download the dart and code runner plugins.

 

Guess you like

Origin www.cnblogs.com/gongyuhonglou/p/12701108.html