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,67 +1,36 @@
import 'dart:async';
import 'package:PiliPlus/common/widgets/loading_widget.dart';
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
import 'package:PiliPlus/common/widgets/self_sized_horizontal_list.dart';
import 'package:PiliPlus/http/loading_state.dart';
import 'package:PiliPlus/pages/common/common_page.dart';
import 'package:PiliPlus/pages/live/controller.dart';
import 'package:PiliPlus/pages/live/widgets/live_item.dart';
import 'package:PiliPlus/pages/live/widgets/live_item_follow.dart';
import 'package:PiliPlus/utils/utils.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_v.dart';
import 'package:PiliPlus/common/widgets/http_error.dart';
import 'package:PiliPlus/pages/home/index.dart';
import 'package:PiliPlus/pages/main/index.dart';
import '../../utils/grid.dart';
class LivePage extends StatefulWidget {
class LivePage extends CommonPage {
const LivePage({super.key});
@override
State<LivePage> createState() => _LivePageState();
}
class _LivePageState extends State<LivePage>
class _LivePageState extends CommonPageState<LivePage, LiveController>
with AutomaticKeepAliveClientMixin {
late final _controller = Get.put(LiveController());
@override
LiveController controller = Get.put(LiveController());
@override
bool get wantKeepAlive => true;
@override
void initState() {
super.initState();
_controller.scrollController.addListener(listener);
}
void listener() {
StreamController<bool> mainStream =
Get.find<MainController>().bottomBarStream;
StreamController<bool> searchBarStream =
Get.find<HomeController>().searchBarStream;
final ScrollDirection direction =
_controller.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() {
_controller.scrollController.removeListener(listener);
super.dispose();
}
@override
Widget build(BuildContext context) {
super.build(context);
@@ -74,14 +43,14 @@ class _LivePageState extends State<LivePage>
),
child: refreshIndicator(
onRefresh: () async {
await _controller.onRefresh();
await controller.onRefresh();
},
child: CustomScrollView(
controller: _controller.scrollController,
controller: controller.scrollController,
physics: const AlwaysScrollableScrollPhysics(),
slivers: [
Obx(
() => _controller.isLogin.value
() => controller.isLogin.value
? SliverPadding(
padding: EdgeInsets.symmetric(
vertical: StyleString.cardSpace,
@@ -98,14 +67,14 @@ class _LivePageState extends State<LivePage>
bottom: MediaQuery.paddingOf(context).bottom + 80,
),
sliver: Obx(
() => _controller.loadingState.value is Loading ||
_controller.loadingState.value is Success
? contentGrid(_controller.loadingState.value)
() => controller.loadingState.value is Loading ||
controller.loadingState.value is Success
? contentGrid(controller.loadingState.value)
: HttpError(
errMsg: _controller.loadingState.value is Error
? (_controller.loadingState.value as Error).errMsg
errMsg: controller.loadingState.value is Error
? (controller.loadingState.value as Error).errMsg
: '没有相关数据',
callback: _controller.onReload,
callback: controller.onReload,
),
),
),
@@ -131,7 +100,7 @@ class _LivePageState extends State<LivePage>
(BuildContext context, int index) {
if (loadingState is Success &&
index == loadingState.response.length - 1) {
_controller.onLoadMore();
controller.onLoadMore();
}
return loadingState is Success
? LiveCardV(
@@ -157,7 +126,7 @@ class _LivePageState extends State<LivePage>
children: [
TextSpan(text: '我的关注 '),
TextSpan(
text: '${_controller.liveCount.value}',
text: '${controller.liveCount.value}',
style: TextStyle(
fontSize: 13,
color: Theme.of(context).colorScheme.primary,
@@ -198,7 +167,7 @@ class _LivePageState extends State<LivePage>
),
],
),
Obx(() => _buildFollowBody(_controller.followListState.value)),
Obx(() => _buildFollowBody(controller.followListState.value)),
],
);
}
@@ -214,7 +183,7 @@ class _LivePageState extends State<LivePage>
gapSize: 5,
childBuilder: (index) {
if (index == loadingState.response.length - 1) {
_controller.fetchLiveFollowing(false);
controller.fetchLiveFollowing(false);
}
return SizedBox(
width: 65,
@@ -275,7 +244,7 @@ class _LivePageState extends State<LivePage>
: const SizedBox.shrink(),
Error() => GestureDetector(
onTap: () {
_controller.fetchLiveFollowing();
controller.fetchLiveFollowing();
},
child: Container(
height: 80,
@@ -294,13 +263,13 @@ class _LivePageState extends State<LivePage>
Widget get _buildFollowListPage => Scaffold(
appBar: AppBar(
title: Obx(
() => Text('${_controller.liveCount.value}人正在直播'),
() => Text('${controller.liveCount.value}人正在直播'),
),
),
body: CustomScrollView(
slivers: [
Obx(
() => _buildFollowListBody(_controller.followListState.value),
() => _buildFollowListBody(controller.followListState.value),
),
],
),
@@ -326,7 +295,7 @@ class _LivePageState extends State<LivePage>
(BuildContext context, int index) {
if (loadingState is Success &&
index == loadingState.response.length - 1) {
_controller.fetchLiveFollowing(false);
controller.fetchLiveFollowing(false);
}
return loadingState is Success
? LiveCardVFollow(
@@ -342,7 +311,7 @@ class _LivePageState extends State<LivePage>
Error() => HttpError(
errMsg: loadingState.errMsg,
callback: () {
_controller
controller
..followListState.value = LoadingState.loading()
..fetchLiveFollowing();
},