Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

get error: This expression has a type of 'void' so its value can't be used By list.add

here is error I got:
This expression has a type of ‘void’ so its value can’t be used By list

So I dont get the point, why in my case it does not work, thanks for any clue

  List<Widget> homePages = [
    buildCoverWidget(),
    buildCoverWidget(),
  ];

   List<Widget> homePagesAddAddPersonPage(){
    homePagesWithAddPersonPage = homePages.add(AddPersonPage()); // here is error .add
    return homePagesWithAddPersonPage;
  }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

add just adds it. It doesn’t return a new list. So just do

List<Widget> homePagesAddAddPersonPage(){
  homePages.add(AddPersonPage());
  return homePages;
}

If you don’t want to modify homePages you could do

List<Widget> homePagesAddAddPersonPage(){
  return [...homePages, AddPersonPage()];
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading