flutter
flutter

Reputation: 6766

Return results in map giving keys, need to access values

I'm trying to return a List from a function

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

here is my map:

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'
    ]
  };

But the returned List<String> is the key value repeated. The length of the list is the length of the corresponding String[] with the key values populating the list. How do I get the values and not the keys into my List?

Upvotes: 0

Views: 272

Answers (1)

Chris Reynolds
Chris Reynolds

Reputation: 5503

The code you published works correctly.

So the fault is in the way you are accessing the result of the function.

If you publish that we may see the problem.

Upvotes: 1

Related Questions