mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-13 20:53:58 +08:00
@@ -142,6 +142,7 @@ class DynamicsController extends GetxController
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
mid.close();
|
||||
tabController.dispose();
|
||||
scrollController.dispose();
|
||||
super.onClose();
|
||||
|
||||
@@ -33,18 +33,18 @@ class _DynamicsTabPageState extends State<DynamicsTabPage>
|
||||
late final DynamicsTabController controller;
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
bool get wantKeepAlive => widget.dynamicsType == .all;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
controller = Get.putOrFind(
|
||||
() =>
|
||||
DynamicsTabController(dynamicsType: widget.dynamicsType)
|
||||
..mid = dynamicsController.mid.value,
|
||||
tag: widget.dynamicsType.name,
|
||||
);
|
||||
super.initState();
|
||||
if (widget.dynamicsType == DynamicsTabType.up) {
|
||||
if (widget.dynamicsType == .up) {
|
||||
_listener = dynamicsController.mid.listen((mid) {
|
||||
if (mid != -1) {
|
||||
controller
|
||||
@@ -58,7 +58,6 @@ class _DynamicsTabPageState extends State<DynamicsTabPage>
|
||||
@override
|
||||
void dispose() {
|
||||
_listener?.cancel();
|
||||
dynamicsController.mid.close();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -71,6 +70,9 @@ class _DynamicsTabPageState extends State<DynamicsTabPage>
|
||||
return controller.onRefresh();
|
||||
},
|
||||
child: CustomScrollView(
|
||||
key: widget.dynamicsType == .all
|
||||
? null
|
||||
: PageStorageKey(widget.dynamicsType),
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
controller: controller.scrollController,
|
||||
slivers: [
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:PiliPlus/common/skeleton/video_card_h.dart';
|
||||
import 'package:PiliPlus/common/widgets/flutter/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/video_card/video_card_h.dart';
|
||||
@@ -9,76 +10,68 @@ import 'package:PiliPlus/utils/grid.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class ZonePage extends StatefulWidget {
|
||||
class ZonePage extends StatelessWidget {
|
||||
const ZonePage({super.key, this.rid, this.seasonType});
|
||||
|
||||
final int? rid;
|
||||
final int? seasonType;
|
||||
|
||||
@override
|
||||
State<ZonePage> createState() => _ZonePageState();
|
||||
}
|
||||
|
||||
class _ZonePageState extends State<ZonePage>
|
||||
with AutomaticKeepAliveClientMixin, GridMixin {
|
||||
late final ZoneController controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
controller = Get.put(
|
||||
ZoneController(rid: widget.rid, seasonType: widget.seasonType),
|
||||
tag: '${widget.rid}${widget.seasonType}',
|
||||
);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
final tag = '$rid$seasonType';
|
||||
final controller = Get.put(
|
||||
ZoneController(rid: rid, seasonType: seasonType),
|
||||
tag: tag,
|
||||
);
|
||||
|
||||
final gridDelegate = Grid.videoCardHDelegate(context);
|
||||
|
||||
Widget buildBody(LoadingState<List<dynamic>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => SliverGrid.builder(
|
||||
gridDelegate: gridDelegate,
|
||||
itemBuilder: (_, _) => const VideoCardHSkeleton(),
|
||||
itemCount: 10,
|
||||
),
|
||||
Success(:final response) =>
|
||||
response != null && response.isNotEmpty
|
||||
? SliverGrid.builder(
|
||||
gridDelegate: gridDelegate,
|
||||
itemBuilder: (context, index) {
|
||||
final item = response[index];
|
||||
if (item is HotVideoItemModel) {
|
||||
return VideoCardH(
|
||||
videoItem: item,
|
||||
onRemove: () => controller.loadingState
|
||||
..value.data!.removeAt(index)
|
||||
..refresh(),
|
||||
);
|
||||
}
|
||||
return PgcRankItem(item: item);
|
||||
},
|
||||
itemCount: response.length,
|
||||
)
|
||||
: HttpError(onReload: controller.onReload),
|
||||
Error(:final errMsg) => HttpError(
|
||||
errMsg: errMsg,
|
||||
onReload: controller.onReload,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
return refreshIndicator(
|
||||
onRefresh: controller.onRefresh,
|
||||
child: CustomScrollView(
|
||||
key: PageStorageKey(tag),
|
||||
controller: controller.scrollController,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.only(top: 7, bottom: 100),
|
||||
sliver: Obx(() => _buildBody(controller.loadingState.value)),
|
||||
sliver: Obx(() => buildBody(controller.loadingState.value)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState<List<dynamic>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => gridSkeleton,
|
||||
Success(:final response) =>
|
||||
response != null && response.isNotEmpty
|
||||
? SliverGrid.builder(
|
||||
gridDelegate: gridDelegate,
|
||||
itemBuilder: (context, index) {
|
||||
final item = response[index];
|
||||
if (item is HotVideoItemModel) {
|
||||
return VideoCardH(
|
||||
videoItem: item,
|
||||
onRemove: () => controller.loadingState
|
||||
..value.data!.removeAt(index)
|
||||
..refresh(),
|
||||
);
|
||||
}
|
||||
return PgcRankItem(item: item);
|
||||
},
|
||||
itemCount: response.length,
|
||||
)
|
||||
: HttpError(onReload: controller.onReload),
|
||||
Error(:final errMsg) => HttpError(
|
||||
errMsg: errMsg,
|
||||
onReload: controller.onReload,
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user