Getting Started with Dart
2022-11-07
Dart Introduction
it is optimized programming language developed by google used to develop mobile and desktop application.- Flutter uses dart language to develop application
- Dart language is C-type Programming language.
- Used to develop single page application
- extension is .dart
Dart syntax
main(){
print("hello");
// this is single line comment
/*
this is
multiline comments
*/
}
Dart data-type
- Number - int, double
- String -
- Boolen
Dart data-type conversion
- String to int :- int.parse("string");
- String to double : double.parse("string");
- Int to String : int_val.toString();
String Interpolation
- Concatination : + is used to concatinate
- Interpolation : ${expression} is used to write expression in between of double quote inside print statement.
- $ : $varname is used to display variable content in between of double quote inside print.
var Keyword
- var keyword is used to define variable without specifying it's type.
- value can be changed by datatype can't
Dynamic keyword
- it is also used to define variable.
- value and data-type both can be changed.
if else, loop and function
main(){
// if else
if( 4 > 2 ){
// true block
}else{
// false block
}
// for loop
for(var i = 0; i < 5; i++){
print(i);
}
// while loop
var j = 4;
while( j < 10 ){
print(j);
j++;
}
// calling function
disp();
}
// defining function
void disp(){
print("hi");
}
OOP Concept
class abc{
void disp(){
print("hi");
}
}
main(){
abc x = abc();//crearing object
x.disp(); // calling function
}