skip to Main Content
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


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search