简体   繁体   中英

How to pass data from one page to another with flutter?

I figured already how to transfer data from one page to another but I found a challenge...

  1. A user has to select one of the matches from pg1 (footballEvent) to go to page2(footballScreen)

footballEvent pg1

  1. Images displayed on page2 should be the same as the ones previous selected from pg1,

footballScreen pg2

  1. This is the code I wrote to pass data from pg1 to pg2. [6]: https://i.stack.imgur.com/u2etq.png the problem with this approach is: leftPlayer[index] , because only the data on the left it's updated on pg2, but not the data on the right side.

  2. This is the code I used inside pg2 to update a team's image data.imageUrl. [5]: https://i.stack.imgur.com/PSkFf.png

  3. This is how I structured the matches: (and I believe this could be the problem because I'm not using the rightPlayer data on the code(3rd point) to pass data to the 2nd pg). leftPlayer and rightPlayer

So, how can I fix this?

You need to pass a values to a next screen class constructor.

Navigator.push(
  context,
  MaterialPageRoute(
    builder: (context) => FootbalScreen(leftPlayer[index]),
  ),
);

RouteSettings useful when you defining routing on an app main class and all routing managed in this class. You can read more about routing organization in Documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM