Map与JSON的转换
1 |
import 'dart:convert'; |
两个List拼接
List.from(lista)..addAll(listb);
List的增删改查
- 增加
list.add();
- 删除指定元素
list.remove(item);
- 删除指定下标元素
list.removeAt(index);
- 修改
list[N] = newValue;
- 查找
list.indexOf(target);
类型转换
- int/double to String
target.toString();
- String to int
int.parse(target);
- String to double
double.parse(target);
按照列表中字典或者实例的某个元素排序
- 类实例:
list.sort((a, b) => b.target.compareTo(a.target));
- 字典:
list.sort((a, b) => b[target].compareTo(a[target]));
定时器
1 |
import 'dart:async'; |
其他
-
保留两位小数点
3.14159.toStringAsFixed(2);
-
null
判断符
isNull ?? '';
-
判断
List
是否为空
List.isEmpty();
-
判断字符串是否包含字符
String.contains(Str);
-
判断
Map
是否包含某个key
Map.containsKey();
-
判断
Map
是否包含某个value
Map.containsValue();
-
判断
Map
是否为空
Map.isEmpty();
-
遍历
Map
Map.forEach((key, value) {...});
-
Map
删除操作- 删除某一项
remove(key);
- 删除满足条件的项
removeWhere((key, value) => [bool]);
- 删除全部
Map.clear();
- 删除某一项
-
Map
浅克隆
Map.from();
-
Map
深克隆1
2
3import 'dart:convert';
// ...
Map clonedUser = json.decode(json.encode(user)); -
Map
追加
Map.addAll(newMap);
近期评论