在提供键的地图中返回结果,需要访问值

时间:2018-11-23 18:33:33

标签: dart flutter

我正在尝试从函数返回列表

List<String> _retrieveUnitList(String categoryName) {
    return headings[categoryName];
  }

这是我的地图:

static const Map<String, List<String>> headings = {
    'People and Society': <String>[
      'Census of Population',
      'Annual Population Estimates',
      'Census Time Series',
      'Birth Deaths & Marriages',
      'Crime & Justice',
      'Social Conditions',
      'Housing and Households',
      'Foreign National Activity ',
      'Information Society'
    ],
    'Labour Market': <String>['Labour Market', 'Earnings'],
    'Economy': <String>[
      'Prices',
      'National Accounts',
      'Balance of Payments',
      'External Trade',
      'Finance'
    ],
    'Environment & Climate': <String>['Environment', 'Climate'],
    'Business Sectors': <String>[
      'Multisectoral',
      'Agriculture and Fishing',
      'Industry',
      'Construction',
      'Services',
      'Transport',
      'Tourism and Travel',
      'Science and Technology'
    ],
    'Public Sector Statistics': <String>[
      'Department of Education and Skills',
      'Irish Maritime Development Office',
      'Sustainable Energy Authority of Ireland',
      'Residential Tenancies Board (RTB)',
      'Health Research Board',
      'Department of Housing, Planning, Community and Local Government',
      'National Roads Authority',
      'Revenue Transport Statistics',
      'Income Tax and Corporation Tax Distribution Statistics',
      'Road Safety Authority of Ireland Statistics',
      'Department of Health',
      'Department of Agriculture Food and the Marine'
    ]
  };

但是返回的List<String>是重复的键值。列表的长度是相应的String[]的长度,其中键值填充列表。如何获取值而不是列表中的键?

1 个答案:

答案 0 :(得分:1)

您发布的代码可以正常工作。

所以错误在于您访问函数结果的方式。

如果您发布,我们可能会发现问题。