This year’s Google I/O introduced to me the Flutter SDK – Google’s mobile app SDK for creating iOS and Android Apps with one language – Dart. With Flutter’s Release Preview being announced I’ve started learning Dart in order to use Flutter and I’ve found it very easy to pick up. I’ll cover an introduction to Dart in this article.
There are four high-level things to know about Dart:
- Object Oriented
Look to work with classes and instances in a built-in manner.
- Statically Typed
The compiler will infer and check types. These types can not be changed (not dynamic) and if you are coming from a dynamically typed language the association of the type with the variable and not the value may seem restrictive.
- C Style Syntax
Dart looks like every other C style language and is familiar. This makes it easy to pick-up if you are familiar with C style languages. If not then its a good place to pick up the syntax style.
- Multiple Run-time Environment
There are three ways to work with Dart output:
B. There is a Dart VM where Dart can run on which gives Dart some legs for server-side execution.
C. And finally as a mobile developer Dart compiles to binary ARM code so that we can produce native apk and ipa files.
Since Dart is statically typed knowing these types is important as well as knowing the following rules:
- Every value has a type.
- Every variable has a type it can reference.
- Once a variable has a type – it can not change.
- You need not annotate every type – Dart can infer the type.
Some types to know which are very familiar are:
- String – ‘hello’
- int – 123
- double – 123.45
- dynamic – the catch all
Dynamic is an interesting one as it breaks the strict type checking allowing a wildcard type (think Any in Swift or id in Objective-C) that can be any of the others.
In the next article I’ll examine Object Oriented Dart.