简体   繁体   中英

How do I run dart code that's isolated from my flutter project without creating a new dart project?

So I'm currently following a tutorial on flutter and it showed this nifty way of running dart code in the same project by creating the new file in the app directory instead of the lib folder. I'm using VS code and can't really figure out how to run the file (they used Android Studio). I tried running the file in the terminal and it kept saying

./scratch.dart: line 1: syntax error near unexpected token `('
./scratch.dart: line 1: `void main() {' 

Any idea what I'm doing wrong?

Run dart in terminal to Check that you have dart installed globally with global environment variable in your terminal. If not follow this doc to install https://dart.dev/get-dart .

After making sure that you have dart SDK installed globally in your PC, you can run any dart file containing a void main function in a terminal like

~$ dart path_to_file/scratch.dart

Note : Running un terminal will not work if you are working with a package that utilize dart:ui

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM