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);

相关推荐
西西学代码15 分钟前
Flutter---头像管理
flutter
2601_9498333919 分钟前
flutter_for_openharmony口腔护理app实战+意见反馈实现
android·javascript·flutter
向哆哆2 小时前
用 Flutter × OpenHarmony 构建智能健康提醒应用:健康档案管理实战
flutter·开源·鸿蒙·openharmony·开源鸿蒙
菜鸟小芯3 小时前
【开源鸿蒙跨平台开发先锋训练营】DAY8~DAY13 底部选项卡&动态功能实现
flutter·harmonyos
向哆哆3 小时前
Flutter × OpenHarmony 实战 | 打造画栈平台的顶部横幅组件
flutter·开源·鸿蒙·openharmony·开源鸿蒙
2501_944525543 小时前
Flutter for OpenHarmony 个人理财管理App实战 - 预算详情页面
android·开发语言·前端·javascript·flutter·ecmascript
雨季6663 小时前
Flutter 三端应用实战:OpenHarmony 简易“动态主题切换卡片”交互模式
flutter·ui·交互·dart
向哆哆3 小时前
构建健康档案管理快速入口:Flutter × OpenHarmony 跨端开发实战
flutter·开源·鸿蒙·openharmony·开源鸿蒙
mocoding4 小时前
使用Flutter强大的图标库fl_chart优化鸿蒙版天气预报温度、降水量、湿度展示
flutter·华为·harmonyos
向哆哆4 小时前
构建智能健康档案管理与预约挂号系统:Flutter × OpenHarmony 跨端开发实践
flutter·开源·鸿蒙·openharmony·开源鸿蒙