My situation is a bit tedious. I am pushing 2 pages to navigator
A - B
B is pushed latest.
For some reasons. I dont want to pop B to navigate from B to A. I want to replace / swap them. The reasons are due to states. I want to keep the states of both A and B pages as there are some widgets which are extremely costly to build (Unity view widget). From B how can I use Navigator so that without destroying my pages I can swap B with A?
Here is the flow:
A opens as the default page.
B is pushed with
Navigator.of(context).pushNamed();
Page Stack is A - B
From B I want to navigate to A while still keeping the B page alive.
-After some magical operations I am missing -
Page Stack is B - A. The user sees the page A. None of the pages were destroyed. They were swapped.
Is there a way to do this in Flutter?
You can use PageView
for simple way and set config like this:
PageController _pagerController = PageController(keepPage: true);
PageView(
physics: NeverScrollableScrollPhysics(),
controller: _pagerController,
children: [
Page_A(),
Page_B(),
],
),
And for switching between pages:
goNextPage() {
_pagerController.animateToPage(
currentPage + 1,
duration: Duration(milliseconds: 500),
curve: Curves.ease,
);
}
goPrevPage() {
_pagerController.animateToPage(
currentPage - 1,
duration: Duration(milliseconds: 500),
curve: Curves.ease,
);
}
I hope it's useful for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With