Last active
June 28, 2018 14:34
-
-
Save graphicbeacon/2adc40ab97cc7f8e645a07c665f70c24 to your computer and use it in GitHub Desktop.
Variables and Built-in types in Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
// Variables and constants | |
var edition = 2; | |
int year = 2011; | |
const language = 'Dart'; | |
String name; // == null | |
// Number | |
var num1 = 5; | |
var num2 = 10.0; | |
print(num1 * num2); | |
print(num1 / num2); | |
print(num1 + num2); | |
print(num1 - num2); | |
// String | |
var str1 = 'Lorem '; | |
String str2 = 'ipsum '; | |
var str3 = str1 + str2 + 'dolor'; | |
var str4 = 'Lorem ' | |
'ipsum $str1' // String interpolation | |
r'amet $str2'; // Raw strings | |
print(str4); | |
// Boolean | |
bool isBrowser = true; | |
var isInvisible = false; | |
print(isBrowser); | |
print(isInvisible); | |
// Function | |
sum(int a, int b) { | |
return a + b; | |
} | |
print(sum(5, 10)); | |
var foo = (a) => print('bar $a'); | |
foo('baz'); | |
// List | |
List fruits = ['banana', 'pineapple', 'mango']; | |
print(fruits.length); | |
fruits.forEach((fruit) => print("I'd like a $fruit")); | |
// Map | |
var user = { | |
"name": 'Sam', | |
"age": 25, | |
"isSubscriber": true, | |
}; | |
print(user["name"]); // Array syntax used as key is not an object property | |
// Runes | |
Runes input = new Runes('I \u2665 Dart'); | |
print(new String.fromCharCodes(input)); | |
// Symbol | |
Symbol simb = #bar; | |
print(simb); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try this snippet in DartPad.