How to run dart in Android studio?

Viewed 5890

Suppose I have a code of Dart typed in Android studio and when I run the app I want it to display the output in Android studio itself.... How can I do it because when I run the code it says me to connect a device....

5 Answers

Just create a dart file with main() method in the lib folder then you can run the file just by right click and select the run option, it will only run that particular dart file instead of your project and it will print the output on the Android Studio console

Example: File name "DartTest.dart"

main() {enter image description here

print('Hellow World');

} enter image description here

Either write it as unit test
or install the Dart SDK and create a Dart project instead of a Flutter project.

enter image description here

1-Run it From Terminal Like running python Scripts: $ dart myFile.dart

dart create dart_test

run this in a command window.

It will create a project in folder dart_test.

From android studio open this project.

dart_test project

Select settings and setup the Flutter sdk folder first.

Flutter SDK path

Press Apply. This will set the Dart SDK also automatically.

Automatically set Dart SDK

Now right click on the bin/dart_test.dart and select Run. You can see the output in the Run Tab below.

Run tab

From now on you can run the program by pressing the Run button on the top toolbar.

Remove the import statement and write fresh code in this file.

Just press the little green color icon and then run your file, but make sure there are no Flutter packages imported in your file otherwise you'll get an error.

enter image description here

Related