rozerro
rozerro

Reputation: 7176

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)?

update: The reason for that behaviour was that I put the main method inside a class. When the main method inside dart file itsef there is an option available in context menu to run this file

Upvotes: 2

Views: 2070

Answers (2)

Mosfeq Anik
Mosfeq Anik

Reputation: 99

After creating a flutter project to run selected dart file as simple dart program 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: 1

HII
HII

Reputation: 4109

Yes, inside that file, right click, and 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
  4. specify path to file in the first field
  5. now there should be an option to run tge file as mentioned above

enter image description here

enter image description here

Upvotes: 1

Related Questions