[英]Flutter Page View how to not always start at the initialPage?
It may sound complicated but I try to explain what Im trying to do听起来可能很复杂,但我试图解释我想要做什么
I have a Page View that contains different pages and also another page view like this:我有一个包含不同页面的页面视图以及另一个像这样的页面视图:
PageView(
controller: pageController,
physics: NeverScrollableScrollPhysics(),
children: [FirstPage(),
SecondPage(),
SmallPageView(),
ThirdPage()])
While this works as intended there is one problem: The SmallPageView()
has 4 Pages.虽然这按预期工作,但存在一个问题: SmallPageView()
有 4 个页面。 When I went through its pages and I am at ThirdPage()
and press the Back Button, which calls:当我浏览它的页面时,我在ThirdPage()
并按下返回按钮,它调用:
pageController.previousPage(duration: Duration(milliseconds: 400), curve: Curves.ease);
I am in SmallPageView()
at page 1 again.我再次在第 1 页的SmallPageView()
中。 Which makes sense since it is the initialPage
and the previousPage
of the pageController
.这是有道理的,因为它是pageController
的initialPage
和previousPage
。 However when I am at ThirdPage()
and press the back button I would like to go to the last page of the SmallPageView()
which is obviously more intuitive但是,当我在ThirdPage()
并按下后退按钮时,我想 go 到SmallPageView()
的最后一页,这显然更直观
I tried doing things like我试着做类似的事情
pageController.previousPage(duration: Duration(milliseconds: 400), curve: Curves.ease);
smallPageViewControllerHouse.jumpToPage(4);
Which doesnt work and I suppose would look ugly.哪个不起作用,我想看起来很难看。
I also cant assign a variable to initialPage of the controller to change it dynamically.我也无法将变量分配给 controller 的 initialPage 以动态更改它。 Is there a way to 'remember' where a page view was instead of starting at the initial page everytime time?有没有办法“记住”页面视图的位置,而不是每次都从初始页面开始?
And of course you could argue to just resolve the SmallPageView()
and put its 4 pages into the PageView()
instead of a nested page view.当然,您可以争论只解决SmallPageView()
并将其 4 个页面放入PageView()
而不是嵌套的页面视图。 But this is a design solution and to achieve the look I am going for there is no other way (as far as I know atm) than doing it with a nested page view但这是一个设计解决方案,为了实现我想要的外观,除了使用嵌套页面视图之外,没有其他方法(据我所知 atm)
try to use IndexedStack, pageview inside indexedstack will maintain it's state尝试使用 IndexedStack,indexedstack 内的页面浏览将保持它的 state
IndexedStack(
index: _currentIndex,
children: [FirstPage(),
SecondPage(),
SmallPageView(),
ThirdPage()])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.