简体   繁体   English

如何从 Flutter 项目中运行选定的 dart 文件作为主要文件?

[英]How to run selected dart file as main from Flutter project?

Is it posibble in Android studio to run selected dart file as simple dart program (not like a flutter app)?是否可以在 Android 工作室中将选定的 dart 文件作为简单的 dart 程序运行(不像 Z5ACEBC7AB70DDBBAE074B0AC)?

update: The reason for that behaviour was that I put the main method inside a class.更新:这种行为的原因是我将主要方法放在 class 中。 When the main method inside dart file itsef there is an option available in context menu to run this file当 dart 文件中的 main 方法时,上下文菜单中有一个选项可用于运行此文件

Yes, inside that file, right click, and select run filename.dart是的,在该文件中,右键单击,然后 select run filename.dart

another way:另一种方式:

  1. press Edit Configuration as in image below按编辑配置,如下图所示
  2. press the + sign to the left按左侧的 + 号
  3. selet dart command line app选择 dart 命令行应用程序
  4. specify path to file in the first field在第一个字段中指定文件路径
  5. now there should be an option to run tge file as mentioned above现在应该有一个选项来运行上面提到的 tge 文件

在此处输入图像描述

在此处输入图像描述

After creating a flutter project to run selected dart file as simple dart program file in Flutter在创建 flutter 项目后,将选定的 dart 文件作为简单的 dart 程序文件运行在 ZC047B10EEE763AFB6164E077CFCC2 中

you have to add main function like below code with you desire class name你必须像下面的代码一样添加主要的 function和你想要的 class 名称

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

or或者

void main() => runApp(newfile()); 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然后 go 到 android 工作室的项目栏右键单击所选文件,您将看到 Run'newfile.dart'然后您还将在工具栏中看到 select 您的应用程序下拉菜单在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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