Home > Software design >  get error: This expression has a type of 'void' so its value can't be used By list.ad
get error: This expression has a type of 'void' so its value can't be used By list.ad

Time:08-19

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

CodePudding user response:

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()];
}
  • Related