opt: live area

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-04-29 20:15:35 +08:00
parent 11a0f2faca
commit fb22e5ab66
5 changed files with 321 additions and 106 deletions

View File

@@ -15,6 +15,8 @@ class LiveController extends CommonListController {
queryData();
}
int? count;
// area
int? areaId;
String? sortType;
@@ -29,6 +31,13 @@ class LiveController extends CommonListController {
Pair<LiveCardList?, LiveCardList?>(first: null, second: null).obs;
final RxBool isLogin = Accounts.main.isLogin.obs;
@override
void checkIsEnd(int length) {
if (count != null && length >= count!) {
isEnd = true;
}
}
@override
List? getDataList(response) {
return response.cardList;
@@ -38,11 +47,15 @@ class LiveController extends CommonListController {
bool customHandleResponse(bool isRefresh, Success response) {
if (isRefresh) {
if (areaIndex.value == 0) {
if (response.response.hasMore == 0) {
isEnd = true;
}
topState.value = Pair(
first: response.response.followItem,
second: response.response.areaItem,
);
} else {
count = response.response.count;
newTags = response.response.newTags;
if (sortType != null) {
tagIndex.value =
@@ -69,6 +82,7 @@ class LiveController extends CommonListController {
@override
Future<void> onRefresh() {
count = null;
currentPage = 1;
isEnd = false;
if (areaIndex.value != 0) {
@@ -109,6 +123,7 @@ class LiveController extends CommonListController {
areaId = cardLiveItem?.areaV2Id;
parentAreaId = cardLiveItem?.areaV2ParentId;
count = null;
currentPage = 1;
isEnd = false;
queryData();
@@ -118,6 +133,7 @@ class LiveController extends CommonListController {
tagIndex.value = index;
this.sortType = sortType;
count = null;
currentPage = 1;
isEnd = false;
queryData();

View File

@@ -147,69 +147,70 @@ class _LivePageState extends CommonPageState<LivePage, LiveController>
childCount: 10,
),
),
Success() => loadingState.response?.isNotEmpty == true
? SliverMainAxisGroup(
slivers: [
if (controller.newTags?.isNotEmpty == true)
SliverToBoxAdapter(
child: SelfSizedHorizontalList(
gapSize: 12,
padding: const EdgeInsets.only(bottom: 8),
childBuilder: (index) {
late final item = controller.newTags![index];
return Obx(
() => SearchText(
fontSize: 13,
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 3,
),
text: '${item.name}',
bgColor: index == controller.tagIndex.value
? theme.colorScheme.secondaryContainer
: Colors.transparent,
textColor: index == controller.tagIndex.value
? theme.colorScheme.onSecondaryContainer
: null,
onTap: (value) {
controller.onSelectTag(
index,
item.sortType,
);
},
),
);
},
itemCount: controller.newTags!.length,
),
),
SliverGrid(
gridDelegate: SliverGridDelegateWithExtentAndRatio(
mainAxisSpacing: StyleString.cardSpace,
crossAxisSpacing: StyleString.cardSpace,
maxCrossAxisExtent: Grid.smallCardWidth,
childAspectRatio: StyleString.aspectRatio,
mainAxisExtent: MediaQuery.textScalerOf(context).scale(90),
),
delegate: SliverChildBuilderDelegate(
(context, index) {
if (index == loadingState.response!.length - 1) {
controller.onLoadMore();
}
final item = loadingState.response![index];
if (item is LiveCardList) {
return LiveCardVApp(
item: item.cardData!.smallCardV1!,
);
}
return LiveCardVApp(item: item);
},
childCount: loadingState.response!.length,
),
Success() => SliverMainAxisGroup(
slivers: [
if (controller.newTags?.isNotEmpty == true)
SliverToBoxAdapter(
child: SelfSizedHorizontalList(
gapSize: 12,
padding: const EdgeInsets.only(bottom: 8),
childBuilder: (index) {
late final item = controller.newTags![index];
return Obx(
() => SearchText(
fontSize: 13,
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 3,
),
text: '${item.name}',
bgColor: index == controller.tagIndex.value
? theme.colorScheme.secondaryContainer
: Colors.transparent,
textColor: index == controller.tagIndex.value
? theme.colorScheme.onSecondaryContainer
: null,
onTap: (value) {
controller.onSelectTag(
index,
item.sortType,
);
},
),
);
},
itemCount: controller.newTags!.length,
),
],
)
: HttpError(onReload: controller.onReload),
),
loadingState.response?.isNotEmpty == true
? SliverGrid(
gridDelegate: SliverGridDelegateWithExtentAndRatio(
mainAxisSpacing: StyleString.cardSpace,
crossAxisSpacing: StyleString.cardSpace,
maxCrossAxisExtent: Grid.smallCardWidth,
childAspectRatio: StyleString.aspectRatio,
mainAxisExtent:
MediaQuery.textScalerOf(context).scale(90),
),
delegate: SliverChildBuilderDelegate(
(context, index) {
if (index == loadingState.response!.length - 1) {
controller.onLoadMore();
}
final item = loadingState.response![index];
if (item is LiveCardList) {
return LiveCardVApp(
item: item.cardData!.smallCardV1!,
);
}
return LiveCardVApp(item: item);
},
childCount: loadingState.response!.length,
),
)
: HttpError(onReload: controller.onReload),
],
),
Error() => HttpError(
errMsg: loadingState.errMsg,
onReload: controller.onReload,