Flutter: update TabController length dynamically

Viewed 22
@override
void initState() {
    _portfoliosTabController = TabController(
      vsync: this,
      length: Provider.of<MyRents>(context, listen: false).list.length,
    );
}

That length changes dynamically depending on many factors and functions and it is given by Provider. How can I update it without moving it inside the build() (that creates other issues)

1 Answers
  1. Every length is changed you should create a new TabController then you have to update the UI every your TabController have new instance
  2. Save the last of index selected to the Variable and Every create new tabController set initialIndex based on last of index selected
Related