英文:
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',然后您还将在工具栏中看到,从运行配置下拉菜单中选择您的应用,如下图所示:
英文:
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
答案3
得分: 0
- 选择文件和编辑配置
- 添加运行外部工具
- 在程序和工作目录中添加
dart
$ProjectFileDir$
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论