Home > Blockchain >  Flutter: TabBar with FutureBuilder or StreamBuilder
Flutter: TabBar with FutureBuilder or StreamBuilder

Time:08-19

I have a TabBar working ok with a FutureBuilder. This executes just once and when I switch between tabs it doesn't need to load again. When I perform some changes to the elements inside this tab I reload it. Until here all good.

The problem is that this is creating some complexity since I have to do now more and more updates to the inner elements.

So having a StreamBuilder fixes the issue but it triggers again when switching tabs. First, the UX is not that good showing the loader every time and second, this is getting documents from Firebase incrementing costs.

Is there a better way to show tabs from Firebase documents?

CodePudding user response:

You can use a StateFulWidget for each page and in the state add the AutomaticKeepAliveClientMixin, this would keep alive each tab and prevent the reload. Hope is useful

class Page extends StatefulWidget {
  Page({Key? key}) : super(key: key);

  @override
  State<Page> createState() => _PageState();
}

class _PageState extends State<Page> with AutomaticKeepAliveClientMixin {
  @override
  Widget build(BuildContext context) {
    return Container();
  }

  @override
  bool get wantKeepAlive => true;
}
  • Related