mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-15 21:53:59 +08:00
@@ -142,6 +142,7 @@ class DynamicsController extends GetxController
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void onClose() {
|
void onClose() {
|
||||||
|
mid.close();
|
||||||
tabController.dispose();
|
tabController.dispose();
|
||||||
scrollController.dispose();
|
scrollController.dispose();
|
||||||
super.onClose();
|
super.onClose();
|
||||||
|
|||||||
@@ -33,18 +33,18 @@ class _DynamicsTabPageState extends State<DynamicsTabPage>
|
|||||||
late final DynamicsTabController controller;
|
late final DynamicsTabController controller;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool get wantKeepAlive => true;
|
bool get wantKeepAlive => widget.dynamicsType == .all;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
super.initState();
|
||||||
controller = Get.putOrFind(
|
controller = Get.putOrFind(
|
||||||
() =>
|
() =>
|
||||||
DynamicsTabController(dynamicsType: widget.dynamicsType)
|
DynamicsTabController(dynamicsType: widget.dynamicsType)
|
||||||
..mid = dynamicsController.mid.value,
|
..mid = dynamicsController.mid.value,
|
||||||
tag: widget.dynamicsType.name,
|
tag: widget.dynamicsType.name,
|
||||||
);
|
);
|
||||||
super.initState();
|
if (widget.dynamicsType == .up) {
|
||||||
if (widget.dynamicsType == DynamicsTabType.up) {
|
|
||||||
_listener = dynamicsController.mid.listen((mid) {
|
_listener = dynamicsController.mid.listen((mid) {
|
||||||
if (mid != -1) {
|
if (mid != -1) {
|
||||||
controller
|
controller
|
||||||
@@ -58,7 +58,6 @@ class _DynamicsTabPageState extends State<DynamicsTabPage>
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_listener?.cancel();
|
_listener?.cancel();
|
||||||
dynamicsController.mid.close();
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +70,9 @@ class _DynamicsTabPageState extends State<DynamicsTabPage>
|
|||||||
return controller.onRefresh();
|
return controller.onRefresh();
|
||||||
},
|
},
|
||||||
child: CustomScrollView(
|
child: CustomScrollView(
|
||||||
|
key: widget.dynamicsType == .all
|
||||||
|
? null
|
||||||
|
: PageStorageKey(widget.dynamicsType),
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
controller: controller.scrollController,
|
controller: controller.scrollController,
|
||||||
slivers: [
|
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/flutter/refresh_indicator.dart';
|
||||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||||
import 'package:PiliPlus/common/widgets/video_card/video_card_h.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:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
class ZonePage extends StatefulWidget {
|
class ZonePage extends StatelessWidget {
|
||||||
const ZonePage({super.key, this.rid, this.seasonType});
|
const ZonePage({super.key, this.rid, this.seasonType});
|
||||||
|
|
||||||
final int? rid;
|
final int? rid;
|
||||||
final int? seasonType;
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
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(
|
return refreshIndicator(
|
||||||
onRefresh: controller.onRefresh,
|
onRefresh: controller.onRefresh,
|
||||||
child: CustomScrollView(
|
child: CustomScrollView(
|
||||||
|
key: PageStorageKey(tag),
|
||||||
controller: controller.scrollController,
|
controller: controller.scrollController,
|
||||||
physics: const AlwaysScrollableScrollPhysics(),
|
physics: const AlwaysScrollableScrollPhysics(),
|
||||||
slivers: [
|
slivers: [
|
||||||
SliverPadding(
|
SliverPadding(
|
||||||
padding: const EdgeInsets.only(top: 7, bottom: 100),
|
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