0

I just realized that flutter re-render all pages in histories stack when navigation changes. In my case I don't want to render page below of all my stack page histories. I just want to render my current page only.

First Page

Widget build(BuildContext context){
  print("1st page");
  return RaisedButton(onPressed: goToSecondPage())
}

Second Page

Widget build(BuildContext context){
  print("2nd page");
  return RaisedButton(onPressed: goToThirdPage())
}

Third Page

Widget build(BuildContext context){
  print("3rd page");
  return Text("I am Third Page, The Last");
}

In my implementation I use Navigator.push(context, MaterialPageRoute(builder: (_) => SecondPage()) to navigate.

Log scenario: startup

1st page

go to second page

2nd page
1st page

go to third page

3rd page
2nd page
1st page

back to second page

2nd page
1st page
windupurnomo
  • 1,121
  • 1
  • 11
  • 22

1 Answers1

2

This is the current intended behavior with Flutter, see the conversation here: https://github.com/flutter/flutter/issues/11655

Here is another SO question talking about the same thing: How to deal with unwanted widget build?

And a currently open pull request to change this behavior: https://github.com/flutter/flutter/pull/44731

Yusef
  • 306
  • 1
  • 5