0

I have created a non-static list. With buttons, you can add and delete elements to this list. Now I want to display this list on two screens. On one screen I want to use a ListView, on the other screen a StackCard.builder. My target is that there is only one list at a time - if it is changed in one Screen, it should change identically automatically in the other Screen.

Now to my question: How can I use the list I created in one class in the other class?

I would be very happy about an answer, thanks in advance for all who look at my problem!

Here is the Code for the Screen with the List

Here is the second screen, where I try to show the List with the StackCard.builder

Nico
  • 11
  • 1

1 Answers1

0

Using provider is good option, you can notifylisteners from the class where you have functions for adding etc.. and notify after every function. At the end you can show your list via Consumer. For more info you can check Provider.

Alperen Ekin
  • 258
  • 2
  • 10
  • Thank you for your answer! I tried it and now I have a List, which I can share, but all my Functions don´t work anymore... But may it could be also that the functions work and only the screen doesn't update - it would be really great if you can help me ones more - Thank you! https://stackoverflow.com/questions/64151163/flutter-my-screen-doesnt-update-when-i-update-my-list-in-the-provider-trough-f – Nico Oct 01 '20 at 07:56
  • You can check wheter it works or not in debug mode however if function works your value supposed to update because you do it with provider. I ll check your post :) – Alperen Ekin Oct 01 '20 at 11:19