feat:分类切换优化
This commit is contained in:
parent
5c00e4efef
commit
311e4fe06c
@ -1,4 +1,5 @@
|
||||
import 'package:easy_refresh/easy_refresh.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_kinetra/kt_model/kt_home_category_bean.dart';
|
||||
import 'package:flutter_kinetra/kt_pages/kt_home/state.dart';
|
||||
import 'package:get/get.dart';
|
||||
@ -10,6 +11,7 @@ import '../../kt_widgets/kt_status_widget.dart';
|
||||
|
||||
class KtHomeLogic extends GetxController {
|
||||
final state = KtHomeState();
|
||||
late TabController categoryTabCtrl;
|
||||
|
||||
final EasyRefreshController easyRefreshController = EasyRefreshController(
|
||||
controlFinishRefresh: true,
|
||||
|
@ -19,10 +19,11 @@ class KtHomePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _KtHomePageState extends State<KtHomePage>
|
||||
with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
|
||||
with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
|
||||
final logic = Get.put(KtHomeLogic());
|
||||
final state = Get.find<KtHomeLogic>().state;
|
||||
late TabController tabCtrl;
|
||||
TabController? categoryTabCtrl;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -537,6 +538,7 @@ class _KtHomePageState extends State<KtHomePage>
|
||||
onTap: () {
|
||||
if (state.selCategoryId == item.categoryId!) return;
|
||||
state.selCategoryId = item.categoryId!;
|
||||
categoryTabCtrl?.animateTo(state.categoryList.indexOf(item));
|
||||
logic.getCategoryVideoList(isRefresh: true);
|
||||
},
|
||||
child: Container(
|
||||
@ -586,7 +588,21 @@ class _KtHomePageState extends State<KtHomePage>
|
||||
// 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),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1441,9 +1457,10 @@ class _KtHomePageState extends State<KtHomePage>
|
||||
);
|
||||
}
|
||||
|
||||
Widget categoryVideoView() {
|
||||
Widget categoryVideoView(int index) {
|
||||
return GetBuilder<KtHomeLogic>(
|
||||
id: 'category-list',
|
||||
key: ValueKey('category-$index'),
|
||||
builder: (ctrl) {
|
||||
if (state.categoryLoadStatus == KtLoadStatusType.loadNoData) {
|
||||
return KtStatusWidget(
|
||||
@ -1544,6 +1561,7 @@ class _KtHomePageState extends State<KtHomePage>
|
||||
@override
|
||||
void dispose() {
|
||||
tabCtrl.dispose();
|
||||
categoryTabCtrl?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user