Last active
December 23, 2020 03:32
-
-
Save numoonchld/e33d36ad5cb4af59c9d5c595aef9b982 to your computer and use it in GitHub Desktop.
flutter tutorial dart primer | https://www.youtube.com/watch?v=FLQ-Vhw1NYQ&list=PL4cUxeGkcC9jLYyp2Aoh6hcWuxFDX6PBJ&index=3
This file contains hidden or 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
// Define main function | |
void main() { | |
// 00. HELLO WORLD ============================ | |
// Hello World Program | |
print('hello world'); | |
// 01. DATA TYPES ============================ | |
print('\n01. DATA TYPES: \n------------------------------'); | |
// Define int and check datatype | |
int age = 31; | |
print(age); | |
print(age.runtimeType); | |
// Define String and check datatype | |
String name = 'numoonchld'; | |
print(name); | |
// name = 30 // Throws "Error: A value of type 'int' can't be assigned to a variable of type 'String'." | |
name = "Raghavendra"; // String overriding is allowed | |
print(name); | |
print(name.runtimeType); | |
// Define boolean and check datatype | |
bool isNight = true; | |
print(isNight); | |
print(isNight.runtimeType); | |
// Dynamic datatype | |
dynamic word = "realize"; | |
print(word); | |
print(word.runtimeType); | |
word = 30; // No error thrown when overwriting with different data type | |
print(word); | |
print(word.runtimeType); | |
// 02. FUNCTIONS ============================ | |
print('\n02. FUNCTIONS: \n------------------------------'); | |
String greeting() { | |
return "Hello"; | |
} | |
int getAge() => 31; // supports single-line arrow functions | |
// Specifying ~void~ return type | |
void voidFuncTest(){ | |
// return "hello"; // Not allowed to return anything - throws "Error: Can't return a value from a void function." | |
print("Hello World"); | |
String greet = greeting(); | |
int age = getAge(); | |
print(age); | |
print(greet); | |
} | |
voidFuncTest(); | |
// 03. LISTS ============================ | |
print('\n03. LISTS: \n------------------------------'); | |
// Dynamic Lists | |
List fruit = ['apple', 'watermelon', 'plums']; | |
print(fruit); | |
print(fruit.runtimeType); | |
fruit.add('banana'); | |
print(fruit); | |
fruit.remove('apple'); | |
print(fruit); | |
fruit.add(31); | |
print(fruit); | |
// Type-Defined Lists | |
List<String> veggies = ['carrot','radish','turnip']; | |
print(veggies); | |
// veggies.add(31); // Throws Error: The argument type 'int' can't be assigned to the parameter type 'String'. | |
print(veggies.length); | |
print(veggies[0]); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment