Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
101 views
in Technique[技术] by (71.8m points)

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?

question from:https://stackoverflow.com/questions/65930794/how-to-pass-data-from-one-page-to-another-with-flutter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...