[英]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.所以我目前正在关注关于 flutter 的教程,它通过在 app 目录而不是 lib 文件夹中创建新文件,展示了在同一项目中运行 dart 代码的这种巧妙方法。 I'm using VS code and can't really figure out how to run the file (they used Android Studio).
我正在使用 VS 代码并且无法真正弄清楚如何运行该文件(他们使用了 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.在终端中运行
dart
以检查您是否在终端中使用全局环境变量全局安装了 dart。 If not follow this doc to install https://dart.dev/get-dart .如果不按照此文档安装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 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
注意:如果您使用的是使用
dart:ui
的 package,则运行 un 终端将不起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.