By Alvin Alexander. Last updated: February 3, 2024
If you want to create a Dart project, probably the best way to do that currently is to use Stagehand:
Once you install that you can create new Dart command-line applications like this:
// create a command-line application
stagehand console-full
However, if you just want to create a little Dart project manually, you can also just follow the steps below:
1. Create a project directory
mkdir my_app
2. cd into that directory
cd my_app
3. Create a pubspec.yaml configuration file
vi pubspec.yaml
Add some basic contents:
name: my_app
description: My app
version: 0.0.1
author: alvin
dependencies:
test: ^1.6.0
4. Get any dependencies you added
pub get
5. Start coding your app
Put your Dart source code in a lib directory (or just in the main directory):
mkdir lib
vi lib/my_app.dart
Add source code:
void main() {
print('hello, world');
}
6. Run your Dart app
dart lib/my_app.dart
More information
Depending on your needs, there are other Dart commands available:
dart
dart2aot
dart2js
dartanalyzer
dartaotruntime
dartdevc
dartdoc
dartfmt
Summary
If you needed an example of how to manually create a Dart project, I hope this example is helpful.