[英]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:另一种方式:
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.