Notes for all chapters (courses from MOOC) :
1. Use var to declare variables and assign different types of values. If the value of the variable is not initialized, it defaults to NULL. After the assignment, the data type of the variable is determined. 2. Declare a variable that can only be assigned once using final. 3. Declare constants using const. Const declarations must be compile-time constants (values that can be determined at compile time). 4. Check whether isNaN is a non-number, isEven is an even number, and isOdd isOdd. Abs () absolute value, round() rounded, floor() rounded down, ceil() rounded up, toInt() converted to integer, and toDouble converted to float. ~/ divide and then round. 5. Use three quotation marks to define a multi-line string. Adding "\n" to a string also begins with a line break. String quotes preceded by "r" will not escape. "+" adds multiple strings. "*n" copies the string n times. "==" is used to determine whether two strings are equal. "[n]" is used to remove the NTH index substring in a string. Use "${}" to print the value of an expression. Do not add "{}" to print the value of a single variable. Length Indicates the length of the printed string. "IsEmpty" determines whether the string isEmpty. Does contains() contain a string? Substring (startIndex,endIndex) Intercepts a string. Whether startsWith() startsWith a string. "EndsWith () endsWith a string." "IndexOf ()" the indexOf a string. LastIndexOf () "The last occurrence of the index of a string." "ToLowerCase ()" toLowerCase, "toUpperCase()" toUpperCase. Trim () clears Spaces. TrimLeft () "Clear the space in front." TrimRight () "Clear space after." Split () "Split string." Replace (),replaceAll(' old ', 'new') "replaces the string. Var List =[1,2,3]; Var List =const[1,2,3] Var list=new list (); . List. length Prints the length of the array. List.add (element) Adds elements. List. Insert (index,value) adds elements to the specified index position. Remove (element) Removes an element. List.clear () clears the array of elements. Returns the indexOf the specified element if it is found, or -1 if it is not found. List.sort () sorts the array by ASCII. List. sublist(start,end) Intercepts a string. List.foreach (print) prints the elements in the list, and you can also pass in custom methods. 7. Create a Map. Var map1={key1 :value1, key2: value2}. Create immutable Map:var map2=const{" key1 ":" value1 "} Var map3=vew Map(); The number of key-value pairs in the length dictionary. Whether isEmpty() isEmpty and whether isNotEmpty() isNotEmpty. Keys retrieves all keys. Values gets all values. ContainsKey () Specifies whether it contains a key. ContainsValue () Specifies whether it contains a value. Remove () removes an element. The forEach loop iterates through the dictionary. map.forEach(f); Void f (key, value) {print (" key = ${key}, value = $value "); } list converts to map, list.asmap () automatically adds index asMap key. The type of a variable changes dynamically when it is declared. dynamic 1=10; A = "test". var list=new List<dynamic>(); list.add(1); List. The add (" test "); list.add(true); print(list); 9.?? = assignment operator, int b=5; b?? = 10; If b is empty and has no value, the value 10 is assigned to b, otherwise the value remains unchanged. 10.?? Operator, String a; String b = 'Java'; String c=a?? b; If a has a value, c is equal to a, and if a has no value, c is equal to b. 11. The for... In loop for(var item in list){}. 12. Break Terminates the entire loop and exits the for loop. Continue Terminates the current loop and continues the next loop. 13. The switch... Case statements that are not null must have a break. The continue statement continues execution of the statement that began at the specified location. The Test case 'Java' : print (" Java "); continue Test; After printing Java, it jumps to "Test" to continue execution from top to bottom. 14. Methods are also objects and have a concrete type Function. The return value type and parameter type can be omitted. Arrow syntax: =>expr is {return expr; }. Applies to only one expression. Methods have a return value. If not specified, the default return NULL last sentence is executed. 15. Optional named parameters: {param1,param2}. You can call the function without passing the parameters in curly braces. PrientPerson1 (String name,{int age,String gender}){print(" name=$name,age=$age,gender=$gender "); } printPerson1 (" hao ", the age: 20, gender: "Male"); . Optional position parameters: [param1,param2]. PrientPerson2 (String name,[int age,String gender]){print(" name=$name,age=$age,gender=$gender "); } printPerson2 (18, "good", "FeMale"); If there are specific fixed parameters, it is optional to declare them after the fixed parameters. PrientPerson3 (String name,{int age=30,String gender}){print(" name=$name,age=$age,gender=$gender "); } printPerson3 (18, "good", "FeMale"); When age is not set, the default value of age is 30. 16. Methods can be assigned as objects to other variables. Methods can be passed as parameters to other methods. Function func=printHello; func(); Void printHello () {print (" hello "); Var func=(STR){print(" hi-$STR "); }; Fun (" ABC "); (() {print (" test "); }) (); This writing method is automatically executed. Anonymous method: a() {return (){print(' ABC '); }; } 18. Closure is a method (object). Closures define methods inside other methods. Closures can access local variables inside external methods and hold their state. a() { int count=0; printCount(){ print(count++); } return printCount; } var func=a(); func(); func(); func();Copy the code