BreezeWind
BreezeWind

Reputation: 688

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

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.

Upvotes: 7

Views: 6080

Answers (3)

Jaswinder
Jaswinder

Reputation: 2289

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

Edit Config Run External Tools Change tool settings

Upvotes: 0

Mosfeq Anik
Mosfeq Anik

Reputation: 99

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 enter image description here

Upvotes: 0

jamesblasco
jamesblasco

Reputation: 1892

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.

Upvotes: 8

Related Questions