Skip to content

Commit

Permalink
fix: issues #42 收藏夹只显示前50个视频
Browse files Browse the repository at this point in the history
  • Loading branch information
guozhigq committed Aug 28, 2023
1 parent f7e9fba commit c156468
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
16 changes: 14 additions & 2 deletions lib/pages/favDetail/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class FavDetailController extends GetxController {
bool isLoadingMore = false;
RxMap favInfo = {}.obs;
RxList<FavDetailItemData> favList = [FavDetailItemData()].obs;
RxString loadingText = '加载中...'.obs;
int mediaCount = 0;

@override
void onInit() {
Expand All @@ -27,6 +29,11 @@ class FavDetailController extends GetxController {
}

Future<dynamic> queryUserFavFolderDetail({type = 'init'}) async {
if (type == 'onLoad' && favList.length >= mediaCount) {
loadingText.value = '没有更多了';
return;
}
isLoadingMore = true;
var res = await await UserHttp.userFavFolderDetail(
pn: currentPage,
ps: 20,
Expand All @@ -36,11 +43,16 @@ class FavDetailController extends GetxController {
favInfo.value = res['data'].info;
if (currentPage == 1 && type == 'init') {
favList.value = res['data'].medias;
} else if (type == 'onload') {
mediaCount = res['data'].info['media_count'];
} else if (type == 'onLoad') {
favList.addAll(res['data'].medias);
}
if (favList.length >= mediaCount) {
loadingText.value = '没有更多了';
}
}
currentPage += 1;
isLoadingMore = false;
return res;
}

Expand All @@ -64,6 +76,6 @@ class FavDetailController extends GetxController {
}

onLoad() {
queryUserFavFolderDetail(type: 'onload');
queryUserFavFolderDetail(type: 'onLoad');
}
}
41 changes: 25 additions & 16 deletions lib/pages/favDetail/view.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'dart:async';

import 'package:easy_debounce/easy_throttle.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pilipala/common/skeleton/video_card_h.dart';
import 'package:pilipala/common/widgets/http_error.dart';
import 'package:pilipala/common/widgets/network_img_layer.dart';
import 'package:pilipala/common/widgets/no_data.dart';
import 'package:pilipala/pages/favDetail/index.dart';

import 'widget/fav_video_card.dart';
Expand Down Expand Up @@ -37,10 +40,9 @@ class _FavDetailPageState extends State<FavDetailPage> {

if (_controller.position.pixels >=
_controller.position.maxScrollExtent - 200) {
if (!_favDetailController.isLoadingMore) {
_favDetailController.isLoadingMore = true;
EasyThrottle.throttle('favDetail', const Duration(seconds: 1), () {
_favDetailController.onLoad();
}
});
}
},
);
Expand Down Expand Up @@ -183,12 +185,7 @@ class _FavDetailPageState extends State<FavDetailPage> {
Map data = snapshot.data;
if (data['status']) {
if (_favDetailController.item!.mediaCount == 0) {
return const SliverToBoxAdapter(
child: SizedBox(
height: 300,
child: Center(child: Text('没有内容')),
),
);
return const NoData();
} else {
return Obx(
() => SliverList(
Expand All @@ -207,18 +204,30 @@ class _FavDetailPageState extends State<FavDetailPage> {
);
}
} else {
return const SliverToBoxAdapter(
child: SizedBox(
height: 300,
child: Center(child: Text('加载中')),
),
// 骨架屏
return SliverList(
delegate: SliverChildBuilderDelegate((context, index) {
return const VideoCardHSkeleton();
}, childCount: 10),
);
}
},
),
SliverToBoxAdapter(
child: SizedBox(
height: MediaQuery.of(context).padding.bottom + 20,
child: Container(
height: MediaQuery.of(context).padding.bottom + 60,
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).padding.bottom),
child: Center(
child: Obx(
() => Text(
_favDetailController.loadingText.value,
style: TextStyle(
color: Theme.of(context).colorScheme.outline,
fontSize: 13),
),
),
),
),
)
],
Expand Down

0 comments on commit c156468

Please sign in to comment.