opt: pages

Closes #644

Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
bggRGjQaUbCoE
2025-04-09 00:22:33 +08:00
parent 850e5a199e
commit 03830533eb
12 changed files with 203 additions and 348 deletions

View File

@@ -1,21 +1,17 @@
import 'dart:async';
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/pages/common/common_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:get/get.dart';
import 'package:PiliPlus/common/constants.dart';
import 'package:PiliPlus/common/skeleton/video_card_h.dart';
import 'package:PiliPlus/common/widgets/http_error.dart';
import 'package:PiliPlus/common/widgets/video_card_h.dart';
import 'package:PiliPlus/pages/home/index.dart';
import 'package:PiliPlus/pages/main/index.dart';
import 'package:PiliPlus/pages/rank/zone/index.dart';
import '../../../utils/grid.dart';
class ZonePage extends StatefulWidget {
class ZonePage extends CommonPage {
const ZonePage({super.key, required this.rid});
final int rid;
@@ -24,52 +20,26 @@ class ZonePage extends StatefulWidget {
State<ZonePage> createState() => _ZonePageState();
}
class _ZonePageState extends State<ZonePage>
class _ZonePageState extends CommonPageState<ZonePage, ZoneController>
with AutomaticKeepAliveClientMixin {
late ZoneController _zoneController;
@override
late ZoneController controller = Get.put(
ZoneController(zoneID: widget.rid),
tag: widget.rid.toString(),
);
@override
bool get wantKeepAlive => true;
@override
void initState() {
super.initState();
_zoneController =
Get.put(ZoneController(zoneID: widget.rid), tag: widget.rid.toString());
_zoneController.scrollController.addListener(listener);
}
void listener() {
StreamController<bool> mainStream =
Get.find<MainController>().bottomBarStream;
StreamController<bool> searchBarStream =
Get.find<HomeController>().searchBarStream;
final ScrollDirection direction =
_zoneController.scrollController.position.userScrollDirection;
if (direction == ScrollDirection.forward) {
mainStream.add(true);
searchBarStream.add(true);
} else if (direction == ScrollDirection.reverse) {
mainStream.add(false);
searchBarStream.add(false);
}
}
@override
void dispose() {
_zoneController.scrollController.removeListener(listener);
super.dispose();
}
@override
Widget build(BuildContext context) {
super.build(context);
return refreshIndicator(
onRefresh: () async {
await _zoneController.onRefresh();
await controller.onRefresh();
},
child: CustomScrollView(
controller: _zoneController.scrollController,
controller: controller.scrollController,
slivers: [
SliverPadding(
// 单列布局 EdgeInsets.zero
@@ -78,17 +48,15 @@ class _ZonePageState extends State<ZonePage>
bottom: MediaQuery.of(context).padding.bottom + 80,
),
sliver: Obx(
() => _zoneController.loadingState.value is Loading
() => controller.loadingState.value is Loading
? _buildSkeleton()
: _zoneController.loadingState.value is Success
? _buildBody(
_zoneController.loadingState.value as Success)
: controller.loadingState.value is Success
? _buildBody(controller.loadingState.value as Success)
: HttpError(
errMsg: _zoneController.loadingState.value is Error
? (_zoneController.loadingState.value as Error)
.errMsg
errMsg: controller.loadingState.value is Error
? (controller.loadingState.value as Error).errMsg
: '没有相关数据',
callback: _zoneController.onReload,
callback: controller.onReload,
),
),
),