当前位置:网站首页>Dart tips
Dart tips
2022-06-30 08:17:00 【yyqx&xxxx】
dart Little knowledge - Dart Is an object-oriented programming language
- var- According to the character
var It can be used to represent many different data types ,int,double,list Both can be used. var Express .
string Types and integers cannot be mixed , Use both var Express , But logic is wrong .
1,final: Assigned once , It can be the object , character string , Numbers etc. , Variable used to modify the expression of a value .
const: Set an explicit value .
2,Boolean Boolean type : Used to judge , The value is true or false.
var sex = true; var sex = false
if(sex){ if(sex){
3,List type ( Array )
- Basic operation : increase , Delete , Change , check
- increase :add
addAll—— Batch addition
insert—— Add... At the specified location insert(n, Number to be added )
insertAll—— Batch add - reduce :remove
remove—— Delete eligible elements
clear—— Delete all elements
removeAt—— Specify location search delete removeAt( Delete , Don't delete ) The principle of moving left and not moving right
*1.start and end Must be effective , The value range is 0 <= start <= end <= length
*2. The removed array cannot be a fixed length array - Change :setRange—— Modify an interval element
setAll—— Modify the italicized elements after searching
replaceRange—— Replace
fillRange—— Replace an interval with a fixed value
getRange—— Get the value of an interval - check :singleWhere
- increase :add
//List<int m = [8, 12, 4, 1, 17, 33, 10];
int a = m.singleWhere((n) => n > 30); //33
int b =m.singleWhere((n) => n > 10); // Report errors
int c = m.singleWhere((n) => n > 10, orElse: () => -1); // Report errors
int d = m.singleWhere((n) => n > 40, orElse: () => -1); //-1
** In the use of singleWhere when , it is to be noted that The following points :
When there is only one element in the array that meets the condition , Return the element
When there are multiple qualified elements in the array , Report errors
When there are multiple qualified elements in the array , Even if it's set orElse , also Will report a mistake
When there is no element in the array that meets the condition , return orElse Specified return value
- subList(n)—— Return from index n After the value of
subList(m,n)—— Return from m To n Value
**any—— Determine whether there are elements in the array that meet the requirements
print(list.any((v) => v > 2));
every—— Determine whether the elements in the array meet the requirements
contains—— Determine whether the array contains an element
4.Map type —— Mapping function
- Define fixed type arrays :List<int ()–List<string ()
Define a fixed length array :List(n)
Define a mixed type array :List<dynamic ()
Define array length :List.length
Array in reverse order :reversed
Determine whether the array is empty :isEmoty
// var list = [1, 2, 3, 4;
print(list.isEmpty); //false;
## Determine whether the array is non empty :isNotEmpty
List[n]=n+1
function and class
function —— By setting the function law , Process the data , To realize a certain function is the function of a programming language .
class —— In object-oriented programming , A function that matches an object .( It's a special function )
- Function return value :
- All functions have return values return
- If the return value of the function is not specified , The default return value is null
- Functions that do not return values , The system will add implicit return sentence
// main(){
bool m(String str1,String str2){
return str1 != str2;
}
String str1="YYQX";
String str2="SXX";
print(m(str1,str2));
}
//main(){
bool m(int a, int b) {
return a == b;
}
int a = 1;
int b = 2;
print(m(a, b));
}
- Optional parameters ——a There are three variables in it :name1,name2,c; among c It's an optional parameter . b Is a string variable ,$ String names can be used to introduce strings . stay c When it's worth it ,b The second half of the sentence will be displayed , On the contrary, it does not show .
// main() {
String a(String name1, String name2, [String c = "YYQX"]) {
var b = '$name1 like $name2';
if (c != null) {
b = '$b like $c';
}
return b;
}
print(a('YYQX', 'SXX'));
}
边栏推荐
- 奇迹MU服务器租用选择 真实好用 稳定不卡 还能防入侵
- JS代码案例
- Is it difficult to jump job ByteDance? With these skills, you can easily pass
- 直击产业落地 | 飞桨重磅推出业界首个模型选型工具
- 【NVMe2.0b 14-1】Abort、Asynchronous Event Request、Capacity Management command
- Why don't you know what to do after graduation from university?
- Getordefault method of map class
- 【NVMe2.0b 14-4】Directive Send/Receive command
- 1162 Postfix Expression
- Development technology sharing of Jingtan NFT digital collection system
猜你喜欢
F12抓包用于做postman接口测试的全过程解析
Deep learning - networks in networks and 1x1 convolution
Sword finger offer II 076 The kth largest number in the array (use heap to solve TOPK problem)
Redis设计与实现(八)| 事务
[nvme2.0b 14-8] set features (Part 2)
【Tensorflow-gpu】window11下深度学习环境搭建
Oracle expansion table space installed in docker
【NVMe2.0b 14-3】Doorbell Buffer Config command、Device Self-test command
Want to change careers, but don't know what to do? This article is written for you who are confused
Wechat applet reports errors using vant web app
随机推荐
【NVMe2.0b 14-5】Firmware Download/Commit command
【NVMe2.0b 14-3】Doorbell Buffer Config command、Device Self-test command
An example of a single service in a cloud project driven by a domain
Redis设计与实现(六)| 集群(分片)
Transformer architecture understanding
鲸探NFT数字臧品系统开发技术分享
【花雕体验】13 搭建ESP32C3之PlatformIO IDE开发环境
奇迹MU服务器租用选择 真实好用 稳定不卡 还能防入侵
Opencv4.2.0+vs2015 configuration
Dlib library blink
Experiment 2 LED button PWM 2021/11/22
Redis设计与实现(一)| 数据结构 & 对象
mysql无法连接内网的数据库
Deep learning - goal orientation
Deep learning vocabulary representation
Wechat official account third-party platform development, zero foundation entry. I want to teach you
【NVMe2.0b 14-1】Abort、Asynchronous Event Request、Capacity Management command
[nvme2.0b 14 - 5] commande de téléchargement / commande du logiciel
我们如何拿到自己满意的薪资呢?这些套路还是需要掌握的
跳槽字节跳动很难嘛?掌握这些技巧,你也能轻松通过