0

I have two questions: First of all how I can print the values of every key (example below). Second, how to pass/iterate it inside build to a custom widget?

I'm new to Dart and Flutter so any help will be appreciated.

var games = [
    {
      'sony': ['Bloodborne', 'Uncharted', 'GOW']
    },
    {
      'Nintendo': ['Mario', 'Zelda', 'Metroid']
    },
    {
      'Microsoft': ['Gears', 'Halo', 'Forza']
    }
  ];

1 Answer 1

1

you can use keys, values, or entries object to achieve your goal.

for (var key in games.keys) print(key); // prints Sony Microsoft
for (var value in games.values) print(value); // prints your values
for (var entry in games.entries) {
  print(entry.key);
  print(entry.value);
}
Sign up to request clarification or add additional context in comments.

8 Comments

thanks for answering but I'm trying to use entries but it inst working Error: The getter 'entries' isn't defined for the class 'List<Map<String, List<String>>>'. same for keys and values.
are you facing any issue while using entries? @LordAhmad
just use entry.value. entry.value is the list so you can use it easily
I don't understand, can you please update your answer above?
if entry.value is not applicable to your requirement then please provide your requirement
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.