0

In the last week I couldn’t’ fix a problem with my app. The problem is I can’t figure out how to use pageview pages separately. Basically i want to add/subtract numbers in one page but don't want to change the numbers on the other ones.

This is my code:

https://gist.github.com/Matelevi12/1d847efe5ace8a25d4676a32332ebd85

Please help me it’s really annoying. I read every article online, but nothing.

Matelevi12
  • 27
  • 6

1 Answers1

0

You will need an array of numbers then for each page.

if you have 3 pages then store the numbers in an array like this

var arrayOfNumbers = [5,5,5];

Then access them using the page index. Use the PageController to access the currently selected page and call that index from the array to retrieve the value saved in the array for that page. If current page is 1 then use arrayOfNumbers[1] to get the specific value for that page.

  • Okey, This is helpful so far, but I will use 30k pages, also how should i store the numbers to the arreyOfnumbers or where should i write the code for the index call? – Matelevi12 Feb 23 '20 at 11:45
  • You can modify your existing methods like this: `void subtractNumbers(int selectedIndex) { setState(() { arrayOfNumbers[selectedIndex] = arrayOfNumbers[selectedIndex] - 1; }); } void addNumbers(int selectedIndex) { setState(() { arrayOfNumbers[selectedIndex] = arrayOfNumbers[selectedIndex] +1; }); }` – Saiful Islam Adar Feb 23 '20 at 11:49
  • Thats pretty good and helpful. Thank you. Can you help me with one more thig. How to use the onPressed function now? – Matelevi12 Feb 23 '20 at 11:55
  • You can use it like `onPressed : (){ subtractNumbers(2) }` – Saiful Islam Adar Feb 25 '20 at 12:13