0

I have this map:

{4: 5, 3: 5, 2: 6, 5: 2, 6: 1, 0: 1, 8: 1, 1: 1}

where the first key is a code from this list

static final List<SensationItem> sensationList = [
    SensationItem(
        code: 0,
        title: 'Formicolio / Intorpidimento'),
    SensationItem(
        code: 1,
        title: 'Sudorazione intensa'),
    SensationItem(
        code: 2, title: 'Dolore al petto'),
    SensationItem(code: 3, title: 'Nausea'),
    SensationItem(code: 4, title: 'Tremori'),
    SensationItem(
        code: 5,
        title: 'Paura di perdere il controllo',
    SensationItem(
        code: 6,
        title: 'Sbandamento / Vertigini'),
    SensationItem(
        code: 7, title: 'Palpitazioni'),
    SensationItem(
        code: 8,
        title: 'Sensazione di soffocamento'),
  ];
}

I want to replace first key with code from sensationList

like something below

var result = ['Formicolio / Intorpidimento',1];
var result2 = ['Sudorazione intensa',8];
var result3 = ['Nausea',5];
var result4 = ['Palpitazioni',15];
.
.
.
.
2
  • This needs clarification. Do you want to generate variables? How Palpitazioni got paired with 15? Commented Feb 18, 2021 at 0:19
  • Yes! I need to add a series of variables in a bar chart. The first key in {4: 5, 3: 5, 2: 6, 5: 2, 6: 1, 0: 1, 8: 1, 1: 1} is code contained in "palpitazioni". {code, quantity} Commented Feb 18, 2021 at 0:22

1 Answer 1

1

This will give you a List<List<Object>>:

final result = myMap.entries
    .map((entry) => [
          sensationList
              .firstWhere((element) => element.code == entry.key)
              .title,
          entry.value
        ])
    .toList();
print(result);
// ([Tremori, 5], [Nausea, 5], [Dolore al petto, 6], ..., [Sensazione di soffocamento, 1], [Sudorazione intensa, 1])

Sign up to request clarification or add additional context in comments.

Comments

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.