Name: Dart
Creator(s): Lars Bak and Kasper Lund
Date: October 10, 2011
Website: dart.dev
Dart is a programming language designed for client development, such as for the web and mobile apps. It is developed by Google and can also be used to build server and desktop applications. Dart is an object-oriented, class-based, garbage-collected language with C-style syntax. Dart can compile to either native code or JavaScript. It supports interfaces, mixins, abstract classes, reified generics, and type inference.
To run a Dart file from the terminal use the command dart run file.dart
.
Variables in Dart are declared using the keyword var
followed by the name of the variable and an =
sign. Constant (unchangeable) variables can be declared with the keyword const
or final
. All lines in Dart must be ended with a semicolon.
var name = 'Jacob';
var num = 42;
const pi = 3.14;
final golden = 1.618;
If/Else statements in Dart are very similar to other languages with the condition in brackets and the body inside curly braces.
if (true) {
print('True!');
} else if (false) {
print('False!');
} else {
print('WTF?!');
}
Dart provides a variety of loop types, a few of which are shown below. To control loops you can use the keywords break
and continue
.
for (var i = 0; i <= 10; i++) {
print(i);
}
var letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];
for (var letter in letters) {
print(letter);
}
var num = 10;
while(num >= 0) {
print(num);
num--;
}
Functions in Dart are also very similar to other languages. They are declared with the name of the function followed by a parameters list in brackets and the body of the function in curly braces.
get_area(width, height) {
return width * height;
}
print(get_area(12, 34));
Classes in Dart are declared with the keyword class
. Constructor functions in a class should have the same name as the class.
class Person {
var name, age;
Person(name, age) {
this.name = name;
this.age = age;
print('${this.name} is ${this.age} years old!');
}
}
- Core Dart Libraries ~ A list of Dart libraries.