Map与JSON的转换
import 'dart:convert';Map user = json.decode(jsonStr);String jsonStr = json.encode(user)
两个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])); 
定时器
import 'dart:async';// 启动定时器Timer _timer = Timer.periodic(const Duration(seconds: 1), callback);// 关闭定时器_timer.cancel();
去除字符串中所有空格
value.replaceAll(new RegExp(r"\s+\b|\b\s|\s|\b"), "").split('');
其他
删除字符串最后一个字符
String a = 'abcd';print(a.substring(0, a.length - 1));
保留两位小数点
3.14159.toStringAsFixed(2);null判断符isNull ?? '';- 判断
List是否为空List.isEmpty(); - 判断字符串是否包含字符
String.contains(Str); - 判断
Map是否包含某个keyMap.containsKey(); - 判断
Map是否包含某个valueMap.containsValue(); - 判断
Map是否为空Map.isEmpty(); - 遍历
MapMap.forEach((key, value) {...}); Map删除操作- 删除某一项
remove(key); - 删除满足条件的项
removeWhere((key, value) => [bool]); - 删除全部
Map.clear(); 
- 删除某一项
 Map浅克隆Map.from();Map深克隆import 'dart:convert';// ...Map clonedUser = json.decode(json.encode(user));
Map追加Map.addAll(newMap);
