Flutter/Dart:如何访问地图/对象中的单个条目 [英] Flutter/Dart: How to access a single entry in a map/object
本文介绍了Flutter/Dart:如何访问地图/对象中的单个条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能是一个非常简单的问题,但是我很难找到答案. 我有一个对象/地图,我不想迭代,但是要在索引处访问特定的键/值.
This might be a very simple question but I am having trouble finding an answer. I have a object/map that I would not like to iterate but access a specific key/value at an index.
例如:
var _results = {
'Key_1' : 'Value_1',
'Key_2' : 'Value_2',
};
我将如何访问索引[1]的key_2和value_2?
How would I access the index[1]'s key_2 and value_2?
我尝试过_results[index]
,_results[index].value
,_results[index].key
和_results[index].toString()
,但是都返回null.
I've tried _results[index]
, _results[index].value
, _results[index].key
and _results[index].toString()
but all returning null.
推荐答案
将值转换为列表:
var _list = _results.values.toList();
通过索引获取:
print(_list[1]);
这篇关于Flutter/Dart:如何访问地图/对象中的单个条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文