如何在Flutter中运行单个Dart文件,而无需在vscode中构建UI?

huangapple go评论78阅读模式
英文:

How to run an individual dart file in Flutter without having to build the UI in vscode?

问题

在Android Studio中,您可以像在dartpad中一样单独运行位于lib文件夹之外的dart文件。我想知道在VSCode中如何执行相同操作。我还没有找到一种方法,可以在不运行和构建整个UI的情况下执行它。

英文:

I know that in Android Studio you could run a dart file that you put out of the lib folder individually much like dartpad. I'm wondering how you could do the same in VSCode. I haven't found a way to do it without it running and building the whole UI.

答案1

得分: 8

你可以像这样从命令行运行 Dart 文件。

$ dart path_to_your_file/your_file_with_main.dart

这将执行文件中的 main() 函数。

英文:

You can run a dart file from the command line like this.

$ dart path_to_your_file/your_file_with_main.dart

This will execute the main() function of the file.

答案2

得分: 0

在创建一个用于在Flutter中单独运行Dart文件的项目之后,您需要像下面的代码一样添加主函数,并替换成您希望使用的类名:

void main() { runApp(NewFile()); }

或者

void main() => runApp(NewFile());

接下来,进入Android Studio项目栏,右键单击所选文件,您将看到运行'newfile.dart',然后您还将在工具栏中看到,从运行配置下拉菜单中选择您的应用,如下图所示:如何在Flutter中运行单个Dart文件,而无需在vscode中构建UI?

英文:

After creating a flutter project to run individually dart file in Flutter

you have to add main function like below code with you desire class name

void main() { runApp(newfile()); }

or

void main() => runApp(newfile());

then go to project bar of android studio right click on the selected file you will see Run'newfile.dart' then you will also see in the toolbar, select your app from the run configurations drop-down menu
like
如何在Flutter中运行单个Dart文件,而无需在vscode中构建UI?

答案3

得分: 0

  1. 选择文件和编辑配置
  2. 添加运行外部工具
  3. 在程序和工作目录中添加 dart $ProjectFileDir$

如何在Flutter中运行单个Dart文件,而无需在vscode中构建UI?
如何在Flutter中运行单个Dart文件,而无需在vscode中构建UI?
如何在Flutter中运行单个Dart文件,而无需在vscode中构建UI?

英文:
  1. Select File and Edit Configuration
  2. Add Run External Tools
  3. Add dart in Program & Working dir $ProjectFileDir$

如何在Flutter中运行单个Dart文件,而无需在vscode中构建UI?
如何在Flutter中运行单个Dart文件,而无需在vscode中构建UI?
如何在Flutter中运行单个Dart文件,而无需在vscode中构建UI?

huangapple
  • 本文由 发表于 2020年1月7日 01:54:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/59616731.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定