Let's try creating a simple program using basic development tools.
- Prerequisite: Dart development environment setup
Creating the First Program in Dart
$ dart help create
Create a new Dart project.
Usage: dart create [arguments] <directory>
-h, --help Print this usage information.
-t, --template The project template to use.
[console-simple (default), console-full, package-simple, server-shelf, web-simple]
--[no-]pub Whether to run 'pub get' after the project has been created.
(defaults to on)
--force Force project generation, even if the target directory already exists.
Run "dart help" to see global options.
Available templates:
console-simple: A simple command-line application. (default)
console-full: A command-line application sample.
package-simple: A starting point for Dart libraries or applications.
server-shelf: A server app using `package:shelf`
web-simple: A web app that uses only core Dart libraries.
$ dart create first-program
Creating first_program using template console-simple...
.gitignore
analysis_options.yaml
CHANGELOG.md
pubspec.yaml
README.md
bin/first_program.dart
Running pub get... 0.9s
Resolving dependencies...
Downloading lints 1.0.1...
Changed 1 dependency!
Created project first_program in first-program! In order to get started, run the following commands:
cd first-program
dart run
$ cd first-program
$ ls
CHANGELOG.md README.md analysis_options.yaml bin pubspec.lock pubspec.yaml
bin/first_program.dart
void main(List<String> arguments) {
print('Hello world!');
}
$ dart run
Building package executable...
Built first_program:first_program.
Hello world!
C C++ C# Clojure Crystal D Erlang F# Go Haskell Java Javascript Julia Kotlin Lua Python Rust Scala Swift Typescript