feat:分类切换优化
This commit is contained in:
parent
0ccd305d72
commit
f53777f26f
@ -133,6 +133,7 @@ class KtHomeLogic extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getCategoryVideoList({bool isRefresh = false}) async {
|
getCategoryVideoList({bool isRefresh = false}) async {
|
||||||
|
state.categoryLoadStatus = KtLoadStatusType.loading;
|
||||||
if (isRefresh) {
|
if (isRefresh) {
|
||||||
state.pageIndex = 1;
|
state.pageIndex = 1;
|
||||||
state.categoryVideoList.clear();
|
state.categoryVideoList.clear();
|
||||||
@ -154,6 +155,7 @@ class KtHomeLogic extends GetxController {
|
|||||||
easyRefreshController.finishRefresh();
|
easyRefreshController.finishRefresh();
|
||||||
easyRefreshController.finishLoad();
|
easyRefreshController.finishLoad();
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
|
state.categoryLoadStatus = KtLoadStatusType.loadSuccess;
|
||||||
List<KtShortVideoBean> list = [
|
List<KtShortVideoBean> list = [
|
||||||
...res.data['list']
|
...res.data['list']
|
||||||
.map(
|
.map(
|
||||||
@ -165,6 +167,13 @@ class KtHomeLogic extends GetxController {
|
|||||||
easyRefreshController.finishLoad(IndicatorResult.noMore);
|
easyRefreshController.finishLoad(IndicatorResult.noMore);
|
||||||
}
|
}
|
||||||
state.categoryVideoList.addAll(list);
|
state.categoryVideoList.addAll(list);
|
||||||
|
if (state.categoryVideoList.isEmpty) {
|
||||||
|
state.categoryLoadStatus = KtLoadStatusType.loadNoData;
|
||||||
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
|
} else {
|
||||||
|
state.categoryLoadStatus = KtLoadStatusType.loadFailed;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import '../../kt_widgets/kt_status_widget.dart';
|
|||||||
|
|
||||||
class KtHomeState {
|
class KtHomeState {
|
||||||
KtLoadStatusType loadStatus = KtLoadStatusType.loading;
|
KtLoadStatusType loadStatus = KtLoadStatusType.loading;
|
||||||
|
KtLoadStatusType categoryLoadStatus = KtLoadStatusType.loading;
|
||||||
List<KtShortVideoBean> topPickList = [];
|
List<KtShortVideoBean> topPickList = [];
|
||||||
List<KtShortVideoBean> hotList = [];
|
List<KtShortVideoBean> hotList = [];
|
||||||
List<KtShortVideoBean> arrivalList = [];
|
List<KtShortVideoBean> arrivalList = [];
|
||||||
|
@ -19,10 +19,11 @@ class KtHomePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _KtHomePageState extends State<KtHomePage>
|
class _KtHomePageState extends State<KtHomePage>
|
||||||
with SingleTickerProviderStateMixin, AutomaticKeepAliveClientMixin {
|
with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
|
||||||
final logic = Get.put(KtHomeLogic());
|
final logic = Get.put(KtHomeLogic());
|
||||||
final state = Get.find<KtHomeLogic>().state;
|
final state = Get.find<KtHomeLogic>().state;
|
||||||
late TabController tabCtrl;
|
late TabController tabCtrl;
|
||||||
|
TabController? categoryTabCtrl;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -132,7 +133,9 @@ class _KtHomePageState extends State<KtHomePage>
|
|||||||
mainAxisAlignment: MainAxisAlignment.end,
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
GestureDetector(
|
||||||
|
onTap: () => Get.toNamed(KtRoutes.search),
|
||||||
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Stack(
|
Stack(
|
||||||
alignment: Alignment.bottomCenter,
|
alignment: Alignment.bottomCenter,
|
||||||
@ -151,6 +154,7 @@ class _KtHomePageState extends State<KtHomePage>
|
|||||||
Image.asset('ic_right.png'.ktIcon, width: 10.w),
|
Image.asset('ic_right.png'.ktIcon, width: 10.w),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
SizedBox(height: 5.w),
|
SizedBox(height: 5.w),
|
||||||
Text(
|
Text(
|
||||||
'Everyone\'s Watching',
|
'Everyone\'s Watching',
|
||||||
@ -532,9 +536,10 @@ class _KtHomePageState extends State<KtHomePage>
|
|||||||
KtHomeCategoryBean item = state.categoryList[index];
|
KtHomeCategoryBean item = state.categoryList[index];
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
if (state.selCategoryId == item.categoryId!) return;
|
||||||
state.selCategoryId = item.categoryId!;
|
state.selCategoryId = item.categoryId!;
|
||||||
|
categoryTabCtrl?.animateTo(state.categoryList.indexOf(item));
|
||||||
logic.getCategoryVideoList(isRefresh: true);
|
logic.getCategoryVideoList(isRefresh: true);
|
||||||
logic.update(['category-items']);
|
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
width: (ScreenUtil().screenWidth - 42.w) / 3,
|
width: (ScreenUtil().screenWidth - 42.w) / 3,
|
||||||
@ -583,7 +588,21 @@ class _KtHomePageState extends State<KtHomePage>
|
|||||||
// return [hotRisingView(), topChartView(), freshDropView()][state.typeList
|
// return [hotRisingView(), topChartView(), freshDropView()][state.typeList
|
||||||
// .indexOf(state.selType)];
|
// .indexOf(state.selType)];
|
||||||
} else {
|
} 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<KtHomePage>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget categoryVideoView() {
|
Widget categoryVideoView(int index) {
|
||||||
return GetBuilder<KtHomeLogic>(
|
return GetBuilder<KtHomeLogic>(
|
||||||
id: 'category-list',
|
id: 'category-list',
|
||||||
|
key: ValueKey('category-$index'),
|
||||||
builder: (ctrl) {
|
builder: (ctrl) {
|
||||||
if (state.categoryVideoList.isEmpty) {
|
if (state.categoryLoadStatus == KtLoadStatusType.loadNoData) {
|
||||||
return KtStatusWidget(
|
return KtStatusWidget(
|
||||||
type: KtErrorStatusType.nothingYet,
|
type: KtErrorStatusType.nothingYet,
|
||||||
onPressed: logic.getCategoryVideoList,
|
onPressed: logic.getCategoryVideoList,
|
||||||
@ -1541,6 +1561,7 @@ class _KtHomePageState extends State<KtHomePage>
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
tabCtrl.dispose();
|
tabCtrl.dispose();
|
||||||
|
categoryTabCtrl?.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user