How to save index of PageView?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have a PageView to show 4 pages and a BottomNavigationBar to switch them. I'm having troubles with the PageController.



In any page, I navigate to a new Screen, but when get back, the PageView return to the initial page and no to the last page.



Here is how I using the PageView



@override
void initState() {
super.initState();
_page = 0;
_pageController = PageController(keepPage: true);
}

return Scaffold(
appBar: AppBar(
title: getAppBarTitle(_page),
centerTitle: true,
actions: renderActions(_page)),
body: PageView(
children: <Widget>[
DashboardScreen(),
InstructionsScreen(),
CatalogScreen(),
ProfileScreen()
],
controller: _pageController,
onPageChanged: onPageChanged,
physics: NeverScrollableScrollPhysics()),
bottomNavigationBar: BottomNavigationBar(
key: bottomNavigationBar,
type: BottomNavigationBarType.shifting,
onTap: navigationTapped,
currentIndex: _page,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home, color: Colors.grey),
activeIcon:
Icon(Icons.home, color: Theme.of(context).primaryColor),
title: Text('Dashboard',
style: TextStyle(color: Theme.of(context).primaryColor)),
backgroundColor: Colors.white),
BottomNavigationBarItem(
icon: Icon(Icons.receipt, color: Colors.grey),
activeIcon:
Icon(Icons.receipt, color: Theme.of(context).primaryColor),
title: Text('Instructions',
style: TextStyle(color: Theme.of(context).primaryColor)),
backgroundColor: Colors.white),
BottomNavigationBarItem(
icon: Icon(Icons.dashboard, color: Colors.grey),
activeIcon:
Icon(Icons.dashboard, color: Theme.of(context).primaryColor),
title: Text('Catalog',
style: TextStyle(color: Theme.of(context).primaryColor)),
backgroundColor: Colors.white),
BottomNavigationBarItem(
icon: Icon(Icons.person, color: Colors.grey),
activeIcon:
Icon(Icons.person, color: Theme.of(context).primaryColor),
title: Text('Profile',
style: TextStyle(color: Theme.of(context).primaryColor)),
backgroundColor: Colors.white)
],
),
);

void navigationTapped(int page) {
_pageController.animateToPage(page,
duration: const Duration(milliseconds: 300), curve: Curves.ease);
}

void onPageChanged(int page) {
setState(() {
this._page = page;
});
}


In the DashboardScreen for example, I go to a new page like:



Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => CodeScreen()))


How can I fix this? I need to use Redux or Bloc to achieve this?



Thanks.










share|improve this question























  • I Tried your Code, work as Expected - i Pushed to new Screen & then pop Back to same Page as Expected & not to _page = 0 .

    – anmol.majhail
    Nov 23 '18 at 19:17











  • Here is a gif of how is working now imgur.com/a/nr2VqtY is weird that the pageview is not retaining the index.

    – Pablo
    Nov 23 '18 at 21:25











  • Could you show us how you are closing your CodeScreen?

    – Chris Reynolds
    Nov 23 '18 at 21:29











  • I'm using the Navigator.pop() and the back button in the AppBar to go back.

    – Pablo
    Nov 27 '18 at 18:38




















0















I have a PageView to show 4 pages and a BottomNavigationBar to switch them. I'm having troubles with the PageController.



In any page, I navigate to a new Screen, but when get back, the PageView return to the initial page and no to the last page.



Here is how I using the PageView



@override
void initState() {
super.initState();
_page = 0;
_pageController = PageController(keepPage: true);
}

return Scaffold(
appBar: AppBar(
title: getAppBarTitle(_page),
centerTitle: true,
actions: renderActions(_page)),
body: PageView(
children: <Widget>[
DashboardScreen(),
InstructionsScreen(),
CatalogScreen(),
ProfileScreen()
],
controller: _pageController,
onPageChanged: onPageChanged,
physics: NeverScrollableScrollPhysics()),
bottomNavigationBar: BottomNavigationBar(
key: bottomNavigationBar,
type: BottomNavigationBarType.shifting,
onTap: navigationTapped,
currentIndex: _page,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home, color: Colors.grey),
activeIcon:
Icon(Icons.home, color: Theme.of(context).primaryColor),
title: Text('Dashboard',
style: TextStyle(color: Theme.of(context).primaryColor)),
backgroundColor: Colors.white),
BottomNavigationBarItem(
icon: Icon(Icons.receipt, color: Colors.grey),
activeIcon:
Icon(Icons.receipt, color: Theme.of(context).primaryColor),
title: Text('Instructions',
style: TextStyle(color: Theme.of(context).primaryColor)),
backgroundColor: Colors.white),
BottomNavigationBarItem(
icon: Icon(Icons.dashboard, color: Colors.grey),
activeIcon:
Icon(Icons.dashboard, color: Theme.of(context).primaryColor),
title: Text('Catalog',
style: TextStyle(color: Theme.of(context).primaryColor)),
backgroundColor: Colors.white),
BottomNavigationBarItem(
icon: Icon(Icons.person, color: Colors.grey),
activeIcon:
Icon(Icons.person, color: Theme.of(context).primaryColor),
title: Text('Profile',
style: TextStyle(color: Theme.of(context).primaryColor)),
backgroundColor: Colors.white)
],
),
);

void navigationTapped(int page) {
_pageController.animateToPage(page,
duration: const Duration(milliseconds: 300), curve: Curves.ease);
}

void onPageChanged(int page) {
setState(() {
this._page = page;
});
}


In the DashboardScreen for example, I go to a new page like:



Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => CodeScreen()))


How can I fix this? I need to use Redux or Bloc to achieve this?



Thanks.










share|improve this question























  • I Tried your Code, work as Expected - i Pushed to new Screen & then pop Back to same Page as Expected & not to _page = 0 .

    – anmol.majhail
    Nov 23 '18 at 19:17











  • Here is a gif of how is working now imgur.com/a/nr2VqtY is weird that the pageview is not retaining the index.

    – Pablo
    Nov 23 '18 at 21:25











  • Could you show us how you are closing your CodeScreen?

    – Chris Reynolds
    Nov 23 '18 at 21:29











  • I'm using the Navigator.pop() and the back button in the AppBar to go back.

    – Pablo
    Nov 27 '18 at 18:38
















0












0








0








I have a PageView to show 4 pages and a BottomNavigationBar to switch them. I'm having troubles with the PageController.



In any page, I navigate to a new Screen, but when get back, the PageView return to the initial page and no to the last page.



Here is how I using the PageView



@override
void initState() {
super.initState();
_page = 0;
_pageController = PageController(keepPage: true);
}

return Scaffold(
appBar: AppBar(
title: getAppBarTitle(_page),
centerTitle: true,
actions: renderActions(_page)),
body: PageView(
children: <Widget>[
DashboardScreen(),
InstructionsScreen(),
CatalogScreen(),
ProfileScreen()
],
controller: _pageController,
onPageChanged: onPageChanged,
physics: NeverScrollableScrollPhysics()),
bottomNavigationBar: BottomNavigationBar(
key: bottomNavigationBar,
type: BottomNavigationBarType.shifting,
onTap: navigationTapped,
currentIndex: _page,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home, color: Colors.grey),
activeIcon:
Icon(Icons.home, color: Theme.of(context).primaryColor),
title: Text('Dashboard',
style: TextStyle(color: Theme.of(context).primaryColor)),
backgroundColor: Colors.white),
BottomNavigationBarItem(
icon: Icon(Icons.receipt, color: Colors.grey),
activeIcon:
Icon(Icons.receipt, color: Theme.of(context).primaryColor),
title: Text('Instructions',
style: TextStyle(color: Theme.of(context).primaryColor)),
backgroundColor: Colors.white),
BottomNavigationBarItem(
icon: Icon(Icons.dashboard, color: Colors.grey),
activeIcon:
Icon(Icons.dashboard, color: Theme.of(context).primaryColor),
title: Text('Catalog',
style: TextStyle(color: Theme.of(context).primaryColor)),
backgroundColor: Colors.white),
BottomNavigationBarItem(
icon: Icon(Icons.person, color: Colors.grey),
activeIcon:
Icon(Icons.person, color: Theme.of(context).primaryColor),
title: Text('Profile',
style: TextStyle(color: Theme.of(context).primaryColor)),
backgroundColor: Colors.white)
],
),
);

void navigationTapped(int page) {
_pageController.animateToPage(page,
duration: const Duration(milliseconds: 300), curve: Curves.ease);
}

void onPageChanged(int page) {
setState(() {
this._page = page;
});
}


In the DashboardScreen for example, I go to a new page like:



Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => CodeScreen()))


How can I fix this? I need to use Redux or Bloc to achieve this?



Thanks.










share|improve this question














I have a PageView to show 4 pages and a BottomNavigationBar to switch them. I'm having troubles with the PageController.



In any page, I navigate to a new Screen, but when get back, the PageView return to the initial page and no to the last page.



Here is how I using the PageView



@override
void initState() {
super.initState();
_page = 0;
_pageController = PageController(keepPage: true);
}

return Scaffold(
appBar: AppBar(
title: getAppBarTitle(_page),
centerTitle: true,
actions: renderActions(_page)),
body: PageView(
children: <Widget>[
DashboardScreen(),
InstructionsScreen(),
CatalogScreen(),
ProfileScreen()
],
controller: _pageController,
onPageChanged: onPageChanged,
physics: NeverScrollableScrollPhysics()),
bottomNavigationBar: BottomNavigationBar(
key: bottomNavigationBar,
type: BottomNavigationBarType.shifting,
onTap: navigationTapped,
currentIndex: _page,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home, color: Colors.grey),
activeIcon:
Icon(Icons.home, color: Theme.of(context).primaryColor),
title: Text('Dashboard',
style: TextStyle(color: Theme.of(context).primaryColor)),
backgroundColor: Colors.white),
BottomNavigationBarItem(
icon: Icon(Icons.receipt, color: Colors.grey),
activeIcon:
Icon(Icons.receipt, color: Theme.of(context).primaryColor),
title: Text('Instructions',
style: TextStyle(color: Theme.of(context).primaryColor)),
backgroundColor: Colors.white),
BottomNavigationBarItem(
icon: Icon(Icons.dashboard, color: Colors.grey),
activeIcon:
Icon(Icons.dashboard, color: Theme.of(context).primaryColor),
title: Text('Catalog',
style: TextStyle(color: Theme.of(context).primaryColor)),
backgroundColor: Colors.white),
BottomNavigationBarItem(
icon: Icon(Icons.person, color: Colors.grey),
activeIcon:
Icon(Icons.person, color: Theme.of(context).primaryColor),
title: Text('Profile',
style: TextStyle(color: Theme.of(context).primaryColor)),
backgroundColor: Colors.white)
],
),
);

void navigationTapped(int page) {
_pageController.animateToPage(page,
duration: const Duration(milliseconds: 300), curve: Curves.ease);
}

void onPageChanged(int page) {
setState(() {
this._page = page;
});
}


In the DashboardScreen for example, I go to a new page like:



Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => CodeScreen()))


How can I fix this? I need to use Redux or Bloc to achieve this?



Thanks.







flutter






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 17:03









PabloPablo

11




11













  • I Tried your Code, work as Expected - i Pushed to new Screen & then pop Back to same Page as Expected & not to _page = 0 .

    – anmol.majhail
    Nov 23 '18 at 19:17











  • Here is a gif of how is working now imgur.com/a/nr2VqtY is weird that the pageview is not retaining the index.

    – Pablo
    Nov 23 '18 at 21:25











  • Could you show us how you are closing your CodeScreen?

    – Chris Reynolds
    Nov 23 '18 at 21:29











  • I'm using the Navigator.pop() and the back button in the AppBar to go back.

    – Pablo
    Nov 27 '18 at 18:38





















  • I Tried your Code, work as Expected - i Pushed to new Screen & then pop Back to same Page as Expected & not to _page = 0 .

    – anmol.majhail
    Nov 23 '18 at 19:17











  • Here is a gif of how is working now imgur.com/a/nr2VqtY is weird that the pageview is not retaining the index.

    – Pablo
    Nov 23 '18 at 21:25











  • Could you show us how you are closing your CodeScreen?

    – Chris Reynolds
    Nov 23 '18 at 21:29











  • I'm using the Navigator.pop() and the back button in the AppBar to go back.

    – Pablo
    Nov 27 '18 at 18:38



















I Tried your Code, work as Expected - i Pushed to new Screen & then pop Back to same Page as Expected & not to _page = 0 .

– anmol.majhail
Nov 23 '18 at 19:17





I Tried your Code, work as Expected - i Pushed to new Screen & then pop Back to same Page as Expected & not to _page = 0 .

– anmol.majhail
Nov 23 '18 at 19:17













Here is a gif of how is working now imgur.com/a/nr2VqtY is weird that the pageview is not retaining the index.

– Pablo
Nov 23 '18 at 21:25





Here is a gif of how is working now imgur.com/a/nr2VqtY is weird that the pageview is not retaining the index.

– Pablo
Nov 23 '18 at 21:25













Could you show us how you are closing your CodeScreen?

– Chris Reynolds
Nov 23 '18 at 21:29





Could you show us how you are closing your CodeScreen?

– Chris Reynolds
Nov 23 '18 at 21:29













I'm using the Navigator.pop() and the back button in the AppBar to go back.

– Pablo
Nov 27 '18 at 18:38







I'm using the Navigator.pop() and the back button in the AppBar to go back.

– Pablo
Nov 27 '18 at 18:38














0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53450572%2fhow-to-save-index-of-pageview%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53450572%2fhow-to-save-index-of-pageview%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Academy of Television Arts & Sciences

L'Équipe

1995 France bombings