0

I am asking for help because I don't know how to solve this issue. I am currently mapping on an Array of object with this code to output an array of string :

                contexts = snapshot.data!.myContexts
                        .where(
                            (e) => e.organisation.name == organizationValue)
                        .map((e) => e.projects.map((e) => e.name)).toList();

The last .toList make the difference in the output value from getting an array of list [()] and a list of list (()).

I wanted to know How I could get only a list of string or an array of string. Thank you in advance, Weac

1
  • 1
    as @esentis pointed out .where returns iterable thus you have list inside list. You can use .firstWhere or first get list with .where and iterate over it and add mapped objects to string to the list Commented Aug 10, 2022 at 10:11

1 Answer 1

1

Can you try creating the list this way ?

final organization = snapshot.data!.myContexts
                        .firstWhere(
                            (e) => e.organisation.name == organizationValue);

contexts = List<String>.generate(organization.projects.length,(index)=>organization.projects[index].name);

Assuming the organization is always unique and you can't have two organization with the same name.

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.