Flutter GetXController 动态Tabbar 报错问题

场景:

1.Tabbar的内容是接口获取的

TabController? tabController;;

在onInit 方法中初始化tabbarController

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

这时候会报一个错误

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

意思就是tabbar初始的length为0 这时去网络请求了title数据 数组长度变成了3 ,而tabController的长度还是0 所以会报错,解决办法就是:

在请求到标题数据后,再给tabbarController 重新赋值就好

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

tabController = TabController(

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

tabController!.animateTo(0);

相关推荐
2501_944424122 小时前
Flutter for OpenHarmony游戏集合App实战之连连看路径连线
android·开发语言·前端·javascript·flutter·游戏·php
小风呼呼吹儿2 小时前
Flutter 框架跨平台鸿蒙开发 - 社区团购记账应用开发教程
flutter·华为·harmonyos
2501_944424129 小时前
Flutter for OpenHarmony游戏集合App实战之贪吃蛇食物生成
android·开发语言·flutter·游戏·harmonyos
不会写代码00010 小时前
Flutter 框架跨平台鸿蒙开发 - 全国景区门票查询应用开发教程
flutter·华为·harmonyos
kirk_wang11 小时前
Flutter艺术探索-Riverpod深度解析:新一代状态管理方案
flutter·移动开发·flutter教程·移动开发教程
猛扇赵四那边好嘴.11 小时前
Flutter 框架跨平台鸿蒙开发 - 旅行规划助手应用开发教程
flutter·华为·harmonyos
2501_9444241214 小时前
Flutter for OpenHarmony游戏集合App实战之俄罗斯方块七种形状
android·开发语言·flutter·游戏·harmonyos
CheungChunChiu15 小时前
Flutter 在嵌入式开发的策略与生态
linux·flutter·opengl
小白阿龙16 小时前
鸿蒙+flutter 跨平台开发——汇率查询器开发实战
flutter·华为·harmonyos·鸿蒙
2501_9444241217 小时前
Flutter for OpenHarmony游戏集合App实战之记忆翻牌配对消除
android·java·开发语言·javascript·windows·flutter·游戏