Last active
August 11, 2023 15:57
-
-
Save TalelMejri/b27898640cfc36d248ead4a08fd13708 to your computer and use it in GitHub Desktop.
dart language Fundamentals
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() { | |
//numbers | |
int counter; //null | |
double pirce; | |
int count=4; | |
double priceProduct=10.5; | |
int? old=int.tryParse("25"); | |
//parsing | |
String stringcount=count.toString(); | |
print(stringcount); | |
//string operations | |
String name="talel"; | |
print(name.toUpperCase() +" "+name.toLowerCase()); | |
print(name.substring(0,4)); | |
bool isAuth=true; | |
//avec var premier type affecté a variable phone ne peut pas étre changer plus tard | |
var phone="29036027"; | |
//phone=445 //error | |
//avec dynamic different que var | |
dynamic id="user"; | |
print(id.runtimeType); //string | |
id=45; | |
print(id.runtimeType);//integer | |
//constants | |
final double textRate=19.5; | |
//textRate=20;//error | |
final List<int> tab=[12,43,45]; | |
tab.add(20); | |
print(tab);// [12, 43, 45, 20] | |
// const block add | |
/*const List<int> tab2=[12,43,45]; | |
tab2.add(20); | |
print(tab2);//Uncaught Error: Unsupported operation: add*/ | |
List<int> numbers=[]; | |
numbers.add(4); | |
numbers.add(5); | |
//numbers.clear(); | |
print(numbers.indexOf(13));//-1 si n'exite pas 13 | |
print(numbers); | |
var student=Map(); | |
student["name"]="talel"; | |
student["age"]="21"; | |
print(student.values); | |
student.putIfAbsent("hama",()=>"Tekto"); | |
student.update('age',(int)=>21); | |
print(student); | |
bool ageCorrect=student["age"]==21 ? true : false; | |
print(ageCorrect); | |
for(int i=0;i<numbers.length;i++) | |
{ | |
print(numbers[i]); | |
} | |
for(int val in numbers){ | |
print(val); | |
} | |
sayHello(); | |
String messgae=getMessage("mejri"); | |
print(messgae); | |
const test=["test1","test2","test3"]; | |
test.forEach((val){ | |
print("${test.indexOf(val)}:$val"); | |
}); | |
} | |
//simple function | |
void sayHello(){ | |
print("hello"); | |
} | |
String getMessage(String name){ | |
return "talel ${name}"; | |
} | |
Future<void> main() async{ | |
print("first"); | |
print(await delayResponse()); | |
print("Five"); | |
} | |
Future<String> delayResponse() async{ | |
print("second"); | |
var future=Future.delayed(Duration(seconds:5),()=>"Third"); | |
print("fourth"); | |
return future; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment