diff --git a/lib/kt_pages/kt_home/logic.dart b/lib/kt_pages/kt_home/logic.dart index b49e0a9..2345c14 100644 --- a/lib/kt_pages/kt_home/logic.dart +++ b/lib/kt_pages/kt_home/logic.dart @@ -133,6 +133,7 @@ class KtHomeLogic extends GetxController { } getCategoryVideoList({bool isRefresh = false}) async { + state.categoryLoadStatus = KtLoadStatusType.loading; if (isRefresh) { state.pageIndex = 1; state.categoryVideoList.clear(); @@ -154,6 +155,7 @@ class KtHomeLogic extends GetxController { easyRefreshController.finishRefresh(); easyRefreshController.finishLoad(); if (res.success) { + state.categoryLoadStatus = KtLoadStatusType.loadSuccess; List list = [ ...res.data['list'] .map( @@ -165,6 +167,13 @@ class KtHomeLogic extends GetxController { easyRefreshController.finishLoad(IndicatorResult.noMore); } state.categoryVideoList.addAll(list); + if (state.categoryVideoList.isEmpty) { + state.categoryLoadStatus = KtLoadStatusType.loadNoData; + } + + update(); + } else { + state.categoryLoadStatus = KtLoadStatusType.loadFailed; update(); } } diff --git a/lib/kt_pages/kt_home/state.dart b/lib/kt_pages/kt_home/state.dart index e555649..795865e 100644 --- a/lib/kt_pages/kt_home/state.dart +++ b/lib/kt_pages/kt_home/state.dart @@ -4,6 +4,7 @@ import '../../kt_widgets/kt_status_widget.dart'; class KtHomeState { KtLoadStatusType loadStatus = KtLoadStatusType.loading; + KtLoadStatusType categoryLoadStatus = KtLoadStatusType.loading; List topPickList = []; List hotList = []; List arrivalList = []; diff --git a/lib/kt_pages/kt_home/view.dart b/lib/kt_pages/kt_home/view.dart index 748fd08..058f900 100644 --- a/lib/kt_pages/kt_home/view.dart +++ b/lib/kt_pages/kt_home/view.dart @@ -19,10 +19,11 @@ class KtHomePage extends StatefulWidget { } class _KtHomePageState extends State - with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin { + with TickerProviderStateMixin, AutomaticKeepAliveClientMixin { final logic = Get.put(KtHomeLogic()); final state = Get.find().state; late TabController tabCtrl; + TabController? categoryTabCtrl; @override Widget build(BuildContext context) { @@ -132,24 +133,27 @@ class _KtHomePageState extends State mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - children: [ - Stack( - alignment: Alignment.bottomCenter, - children: [ - Image.asset('text_bg.png'.ktIcon, height: 17.w), - Text( - 'Trend Cyclone', - style: TextStyle( - fontSize: 14.sp, - color: Color(0xFF1E1E20), - fontWeight: FontWeight.w800, + GestureDetector( + onTap: () => Get.toNamed(KtRoutes.search), + child: Row( + children: [ + Stack( + alignment: Alignment.bottomCenter, + children: [ + Image.asset('text_bg.png'.ktIcon, height: 17.w), + Text( + 'Trend Cyclone', + style: TextStyle( + fontSize: 14.sp, + color: Color(0xFF1E1E20), + fontWeight: FontWeight.w800, + ), ), - ), - ], - ), - Image.asset('ic_right.png'.ktIcon, width: 10.w), - ], + ], + ), + Image.asset('ic_right.png'.ktIcon, width: 10.w), + ], + ), ), SizedBox(height: 5.w), Text( @@ -532,9 +536,10 @@ class _KtHomePageState extends State KtHomeCategoryBean item = state.categoryList[index]; return GestureDetector( onTap: () { + if (state.selCategoryId == item.categoryId!) return; state.selCategoryId = item.categoryId!; + categoryTabCtrl?.animateTo(state.categoryList.indexOf(item)); logic.getCategoryVideoList(isRefresh: true); - logic.update(['category-items']); }, child: Container( width: (ScreenUtil().screenWidth - 42.w) / 3, @@ -583,7 +588,21 @@ class _KtHomePageState extends State // return [hotRisingView(), topChartView(), freshDropView()][state.typeList // .indexOf(state.selType)]; } else { - return categoryVideoView(); + categoryTabCtrl ??= TabController( + length: state.categoryList.length, + vsync: this, + ); + + return Expanded( + child: TabBarView( + controller: categoryTabCtrl, + physics: NeverScrollableScrollPhysics(), + children: List.generate( + state.categoryList.length, + (index) => categoryVideoView(index), + ), + ), + ); } } @@ -1438,11 +1457,12 @@ class _KtHomePageState extends State ); } - Widget categoryVideoView() { + Widget categoryVideoView(int index) { return GetBuilder( id: 'category-list', + key: ValueKey('category-$index'), builder: (ctrl) { - if (state.categoryVideoList.isEmpty) { + if (state.categoryLoadStatus == KtLoadStatusType.loadNoData) { return KtStatusWidget( type: KtErrorStatusType.nothingYet, onPressed: logic.getCategoryVideoList, @@ -1541,6 +1561,7 @@ class _KtHomePageState extends State @override void dispose() { tabCtrl.dispose(); + categoryTabCtrl?.dispose(); super.dispose(); } }