State Management (no cubic, bloc)

We start off with Page 1. Page 1 has two containers with blue. We go to Page 2 in order to change these colors via radio buttons. When we come back to Page 1, the colors have changed. This is how state is shared between two pages.

main.dart

Now, in Page 1, we have two properties. firstSquareColor and secondSquareColor. They are both set to false.

page1.dart

We have Containers that display blue or pink depending on this bool. For false, we display blue for both booleans. We look to Page2’s radio edits in order to know how to color our Containers.

At the very bottom of page 1, we have a button that goes to page2 in order to change radio btns:

It calls _navigateNextPageAndretriveValue in order to use Navigator to navigate to page 2.
Now look at this function _navigateNextPageAndretriveValue:

Basically its an async function because we wait for the results that returns from when the next page (page2) pops.

So let’s see what happens when at page2.

We have two properties to maintain the bools.

page2.dart

So we have a switch that takes this value. When the user clicks on the radio button to switch bool, firstValue and secondValue will be updated due to setState.

page2.dart

Now, when you’re ready, you push the save button. Remember in Page1 where we have the _navigateNextPageAndretriveValue function?
That function is currently awaiting Navigator.push(…). Our page2 is the result of that. And once we Navigator.pop here, with our list of firstValue and secondValue, this list will be returned to _navigateNextPageAndretriveValue.

Now these two bools will be in nextPageValues.

Then in Page 1, we simply set its properties to the values presented in nextPageValues array.

Source

main.dart

page1.dart

page2.dart