简体   繁体   English

如何在不创建新的 dart 项目的情况下运行与我的 flutter 项目隔离的 dart 代码?

[英]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.

相关问题 flutter 和 dart 的新手,通过创建世界时间应用程序来创建初学者项目,但是当我运行代码时会发生这种情况 - new to flutter and dart, creating a beginners project by creating a world time app but this happens when i run the code 如何从 Flutter 项目中运行选定的 dart 文件作为主要文件? - How to run selected dart file as main from Flutter project? 如何在VS Code中的调试中以dart v2模式运行我的flutter应用程序(--preview-dart-2选项) - How do I run my flutter app in dart v2 mode in debug in VS Code (--preview-dart-2 option) Flutter web 在英特尔项目中创建新 ZBB14127678960FAE9157D873950EA2 时在 dart 模板下找不到应用程序选项 - Flutter web app option not found under dart templates while creating new dart project in Intellij IDEA 为 flutter 项目创建 DART 包时出错 - Error while creating DART package for flutter project 这是我在 Android Studio 的 flutter 项目中运行我的 dart 代码时得到的 output - This is the output I get when running my dart code in flutter project in Android Studio 如果您的项目有 dart html 导入,如何在模拟器上运行 flutter - How to run flutter on the emulator if you project has dart html imports 我如何将其变成 Dart? Dart & Flutter - How do I make this into Dart? Dart & Flutter 如何为我的 Flutter Dart 项目制作复杂的 Model? - How to make complex Model for my Flutter Dart Project? 在做 Flutter/Dart 项目时,你如何在 VS 代码中获得这个下拉选择? - How do you get this drop down selection in VS code when doing a Flutter/Dart project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM