Setting up a VS Code playground for Dart
I just want to test out some Dart code. Why does it take so long?
So you see a code snippet you want to try out. Or you have a Dart programming problem you want to try to solve in isolation. What is the fastest way to write that code and get it running?
In the following article I share the journey I took to answer that question.
A Whole New Flutter Project
My introduction to Dart was through Flutter, so naturally I would create a new Flutter project whenever I wanted to test out some Dart code.
This was slow, though. I was using Android Studio, which took a long time to start up. Then I would have to integrate the Dart code somehow into the Flutter UI. I usually did that by adding it to a button’s onPressed
callback.
class HomeWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return RaisedButton(
child: Text('Run'),
onPressed: () {
runCode();
},
);
}
}void runCode() {
print('hello world');
}
Finally, I would have to start up an Android emulator or iOS simulator, which also took forever.
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Running Gradle task…