Flutter GetXController dynamic Tabbar error reporting problem

Scenes:

1.The content of Tabbar is obtained through the interface

2.

  TabController? tabController;;

Initialize tabbarController in onInit method

tabController = TabController(initialIndex: 0, length: titleDataList.length, vsync: this);

An error will be reported at this time

Controller's length property (0) does not match the number of children (3) p,

This means that the initial length of the tabbar is 0. Then the length of the title data array when requested from the network becomes 3, and the length of the tabController is still 0, so an error will be reported. The solution is:

After requesting the title data, just reassign the value to tabbarController.

    print("titleDataList====${titleDataList.length}");

        tabController = TabController(

            initialIndex: 1, length: titleDataList.length, vsync: this);

        tabController!.animateTo(0);

Guess you like

Origin blog.csdn.net/zww986736788/article/details/132385659