statefull page1 {
bool myBool = false ;
}
statefull page2 {
print(page1().myBool ) // this print the value but the printed value does not print the update one
}
i mean if myBool
changed to true it always print false in page 2 ..
note: page2 is stack page above page1 and page 1 still mounted and i want print myBool value from page 2 as if i do it in page 1
2
Answers
When we use
page1()
we are creating a new instance and that’s why it is getting false everytime.You can make it static which will be on class variable but it won’t be for updating ui.
It will be easy for you using callback method https://stackoverflow.com/a/75006895/10157127
If you don’t need to update value from page2, just pass the value as parameter.
or better state management solutions.
use GetX package from pub.dev
GetX is an extra-light and powerful solution for Flutter. It combines high-performance state management, intelligent dependency injection, and route management quickly and practically.
Learn GetX documentation and you can access a variable value from page to other very easy