Dart 从地图中删除元素
如何在地图上进行迭代,逐个删除地图上的元素,然后在删除每个元素后调用一个函数 假设我有释放功能Dart 从地图中删除元素,dart,flutter,Dart,Flutter,如何在地图上进行迭代,逐个删除地图上的元素,然后在删除每个元素后调用一个函数 假设我有释放功能 final HashMap<int, bool> _instances = new HashMap<int, bool>(); void release(dynamic instance) { if (_instances[instance.hashCode] != null) { _releaseHashCode(instance.hashCod
final HashMap<int, bool> _instances = new HashMap<int, bool>();
void release(dynamic instance) {
if (_instances[instance.hashCode] != null) {
_releaseHashCode(instance.hashCode);
_dispatcher.dispatchEvent(PinEvent.release);
}
}
void _releaseHashCode(int hashCode) => _instances.remove(hashCode);
我就是这样做的
void releaseAll() {
var tempMap = new HashMap<int, bool>()..addAll(_instances);
tempMap.forEach((int hashCode, bool value) {
_releaseHashCode(hashCode);
_dispatcher.dispatchEvent(PinEvent.release);
});
tempMap.clear();
tempMap = null;
}
void releaseAll(){
var tempMap=newhashmap()…addAll(_实例);
forEach((int hashCode,bool值){
_释放hashCode(hashCode);
_dispatcher.dispatchEvent(PinEvent.release);
});
tempMap.clear();
tempMap=null;
}
我就是这样做的
void releaseAll() {
var tempMap = new HashMap<int, bool>()..addAll(_instances);
tempMap.forEach((int hashCode, bool value) {
_releaseHashCode(hashCode);
_dispatcher.dispatchEvent(PinEvent.release);
});
tempMap.clear();
tempMap = null;
}
void releaseAll(){
var tempMap=newhashmap()…addAll(_实例);
forEach((int hashCode,bool值){
_释放hashCode(hashCode);
_dispatcher.dispatchEvent(PinEvent.release);
});
tempMap.clear();
tempMap=null;
}
检查removeWhere
final Map<String, dynamic> tempMap = json.decode(jsonValue);
tempMap.removeWhere((String key, dynamic value)=> value==null);
final Map tempMap=json.decode(jsonValue);
tempMap.removeWhere((字符串键,动态值)=>value==null);
检查removeWhere
final Map<String, dynamic> tempMap = json.decode(jsonValue);
tempMap.removeWhere((String key, dynamic value)=> value==null);
final Map tempMap=json.decode(jsonValue);
tempMap.removeWhere((字符串键,动态值)=>value==null);