1

I have this code to manage the bottomNavigationBar, but every time I tap to change page flutter rebuild the widget, how can I not do it?

class _HomePageState extends State<HomePage>{
  int _pageIndex = 0;
  List<Widget> pages = [];

  @override
  void initState() {
    super.initState();

    pages.add(PostListPage());
    pages.add(MessagesPage());
    pages.add(ProfilePage());
    pages.add(SettingsPage());
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("CFA"),
        centerTitle: true
      ),
      body: pages[_pageIndex],
      bottomNavigationBar:buildNavigationBar()
    );
  }
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 2
    You shouldn't worry about that. Flutter calls `build()` every time some state changes that might affect the rendered result. You should build your code so that it works properly no matter how often `build()` is called. If a `build()` method returns the identical instance as before, that widget and its subtree are reused. – Günter Zöchbauer Sep 20 '18 at 14:11
  • But I have some data in the first page, catch on the web. In this method all time it reload the page it realod the data. – Pietro smusso Sep 20 '18 at 14:21
  • 1
    @Pietrosmusso that sounds like a different issue. You should put details like that into the question text with an [edit]. –  Sep 20 '18 at 14:30
  • Take a look at https://stackoverflow.com/questions/52249578/how-to-deal-with-unwanted-widget-build – Rémi Rousselet Sep 20 '18 at 14:39

0 Answers0