Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Basic Dart
- * https://www.tutorialspoint.com/dart_programming/dart_programming_functions.htm
- * https://dartpad.dartlang.org/
- */
- void main() {
- int _int, __int;
- String _string;
- /*
- * Data Type
- * 1. Numbers
- * - int
- * - double
- * 2. Strings
- * - Runes (UTF-32)
- * - String (UTF-16)
- * 3. Boolean
- * - bool
- * 4. List & Map
- * - List (ordered group of objects)
- * - Map (represent set of values as key-value pairs)
- * 5. Dynamic Type
- * - dynamic (if data type not specified || explicitly used)
- */
- /*
- * const = compile-time constant (Implicitly final)
- */
- // ~/ division (return int)
- print("/ = ");
- print(25 / 4);
- print("");
- print("~/ = ");
- print(25 ~/ 4);
- print("");
- /*
- * is = true if object has specified type
- * is! = false if object has specified type
- */
- _int = 5;
- if (_int is int) {
- print("_int is int");
- }
- if (_int is! String) {
- print("_int is not String");
- }
- print("");
- /*
- * expr1 ?? expr2
- * (if expr1 is !NULL then return expr1 else return expr2)
- */
- _int = null;
- __int = 5;
- print(_int ?? __int);
- print("");
- /*
- * Parsing
- * - parse()
- * parse a string into a number
- */
- _string = "123";
- print(num.parse(_string) + 32);
- print("");
- /*
- * String
- * - Single line vs Multi line
- */
- _string = 'Single line';
- print("Current String = ${_string}");
- _string = "Single line";
- print("Current String = ${_string}");
- _string = '''Multi
- line''';
- print("Current String = ${_string}");
- _string = """Multi
- line""";
- print("Current String = ${_string}");
- print("");
- /*
- * List
- * - Fixed Length
- * - Growable
- */
- List listAnimals = new List(5);
- listAnimals[0] = "Dog";
- listAnimals[1] = "Cat";
- listAnimals[2] = "Sheep";
- listAnimals[3] = "Lizard";
- listAnimals[4] = "Bear";
- print("List of Animals = ${listAnimals}");
- List listDogs = new List();
- listDogs.add("Beagle");
- listDogs.add("Pitbull");
- listDogs.add("Bull Dog");
- listDogs.add("Chihuahua");
- listDogs.remove("Bull Dog");
- listDogs.removeAt(0);
- print("List of Dogs = ${listDogs}");
- print("");
- /*
- * Maps
- */
- Map profile = new Map();
- profile = {'Name': 'John Doe', 'Password': 'jonjon'};
- profile['Description'] = 'Looks like a dead body';
- print("Profile: ${profile['Description']}");
- print("");
- /*
- * Symbol
- */
- /*
- * Runes
- */
- Runes _runes = new Runes('\u{1f605}');
- print("Runes: ${new String.fromCharCodes(_runes)}");
- /*
- * Function
- * - [] = optional parameter
- * - {} = optional named parameter
- */
- foo("Hello");
- optionalNamed(myString: "World");
- optionalNamed();
- // Lambada Function / Arrow Function
- lambadaFun();
- }
- foo(String _string, [int _int]) {
- print(_string);
- print(_int);
- }
- optionalNamed({String myString : "Default Value"}) {
- print(myString);
- }
- lambadaFun() => print("This is lambada");
Add Comment
Please, Sign In to add comment