mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: live area page
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
38
lib/pages/live_area_detail/child/controller.dart
Normal file
38
lib/pages/live_area_detail/child/controller.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
import 'package:PiliPlus/http/live.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/live/live_feed_index/card_data_list_item.dart';
|
||||
import 'package:PiliPlus/models/live/live_second_list/data.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
|
||||
class LiveAreaChildController
|
||||
extends CommonListController<LiveSecondData, CardLiveItem> {
|
||||
LiveAreaChildController(this.areaId, this.parentAreaId);
|
||||
final dynamic areaId;
|
||||
final dynamic parentAreaId;
|
||||
|
||||
String? sortType;
|
||||
|
||||
final isLogin = Accounts.main.isLogin;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
queryData();
|
||||
}
|
||||
|
||||
@override
|
||||
List<CardLiveItem>? getDataList(LiveSecondData response) {
|
||||
return response.cardList;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<LiveSecondData>> customGetData() =>
|
||||
LiveHttp.liveSecondList(
|
||||
pn: currentPage,
|
||||
isLogin: isLogin,
|
||||
areaId: areaId,
|
||||
parentAreaId: parentAreaId,
|
||||
sortType: sortType,
|
||||
);
|
||||
}
|
||||
103
lib/pages/live_area_detail/child/view.dart
Normal file
103
lib/pages/live_area_detail/child/view.dart
Normal file
@@ -0,0 +1,103 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/skeleton/video_card_v.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/live/live_feed_index/card_data_list_item.dart';
|
||||
import 'package:PiliPlus/pages/live/widgets/live_item_app.dart';
|
||||
import 'package:PiliPlus/pages/live_area_detail/child/controller.dart';
|
||||
import 'package:PiliPlus/utils/grid.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class LiveAreaChildPage extends StatefulWidget {
|
||||
const LiveAreaChildPage({
|
||||
super.key,
|
||||
required this.areaId,
|
||||
required this.parentAreaId,
|
||||
});
|
||||
|
||||
final dynamic areaId;
|
||||
final dynamic parentAreaId;
|
||||
|
||||
@override
|
||||
State<LiveAreaChildPage> createState() => _LiveAreaChildPageState();
|
||||
}
|
||||
|
||||
class _LiveAreaChildPageState extends State<LiveAreaChildPage>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
late final _controller = Get.put(
|
||||
LiveAreaChildController(widget.areaId, widget.parentAreaId),
|
||||
tag: '${widget.areaId}${widget.parentAreaId}',
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return refreshIndicator(
|
||||
onRefresh: _controller.onRefresh,
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
left: StyleString.safeSpace,
|
||||
right: StyleString.safeSpace,
|
||||
top: StyleString.safeSpace,
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 80,
|
||||
),
|
||||
sliver: Obx(() => _buildBody(_controller.loadingState.value)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState<List<CardLiveItem>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => 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) {
|
||||
return const VideoCardVSkeleton();
|
||||
},
|
||||
childCount: 10,
|
||||
),
|
||||
),
|
||||
Success() => 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();
|
||||
}
|
||||
return LiveCardVApp(item: loadingState.response![index]);
|
||||
},
|
||||
childCount: loadingState.response!.length,
|
||||
),
|
||||
)
|
||||
: HttpError(
|
||||
onReload: _controller.onReload,
|
||||
),
|
||||
Error() => HttpError(
|
||||
errMsg: loadingState.errMsg,
|
||||
onReload: _controller.onReload,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
38
lib/pages/live_area_detail/controller.dart
Normal file
38
lib/pages/live_area_detail/controller.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:PiliPlus/http/live.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/live/live_area_list/area_item.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
|
||||
class LiveAreaDatailController
|
||||
extends CommonListController<List<AreaItem>?, AreaItem> {
|
||||
LiveAreaDatailController(this.areaId, this.parentAreaId);
|
||||
final dynamic areaId;
|
||||
final dynamic parentAreaId;
|
||||
|
||||
late int initialIndex = 0;
|
||||
final isLogin = Accounts.main.isLogin;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
queryData();
|
||||
}
|
||||
|
||||
@override
|
||||
List<AreaItem>? getDataList(List<AreaItem>? response) {
|
||||
if (response?.isNotEmpty == true) {
|
||||
initialIndex = max(0, response!.indexWhere((e) => e.id == areaId));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<List<AreaItem>?>> customGetData() =>
|
||||
LiveHttp.liveRoomAreaList(
|
||||
isLogin: isLogin,
|
||||
parentid: parentAreaId,
|
||||
);
|
||||
}
|
||||
94
lib/pages/live_area_detail/view.dart
Normal file
94
lib/pages/live_area_detail/view.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
import 'package:PiliPlus/common/widgets/scroll_physics.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/live/live_area_list/area_item.dart';
|
||||
import 'package:PiliPlus/pages/live_area_detail/child/view.dart';
|
||||
import 'package:PiliPlus/pages/live_area_detail/controller.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class LiveAreaDetailPage extends StatefulWidget {
|
||||
const LiveAreaDetailPage({
|
||||
super.key,
|
||||
required this.areaId,
|
||||
required this.parentAreaId,
|
||||
required this.parentName,
|
||||
});
|
||||
|
||||
final dynamic areaId;
|
||||
final dynamic parentAreaId;
|
||||
final String parentName;
|
||||
|
||||
@override
|
||||
State<LiveAreaDetailPage> createState() => _LiveAreaDetailPageState();
|
||||
}
|
||||
|
||||
class _LiveAreaDetailPageState extends State<LiveAreaDetailPage> {
|
||||
late final _controller = Get.put(
|
||||
LiveAreaDatailController(widget.areaId?.toString(), widget.parentAreaId));
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final ThemeData theme = Theme.of(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(widget.parentName),
|
||||
actions: [
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
// TODO: search
|
||||
},
|
||||
icon: const Icon(Icons.search),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
bottom: false,
|
||||
child: Obx(() => _buildBody(theme, _controller.loadingState.value)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(
|
||||
ThemeData theme, LoadingState<List<AreaItem>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => const SizedBox.shrink(),
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? DefaultTabController(
|
||||
initialIndex: _controller.initialIndex,
|
||||
length: loadingState.response!.length,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TabBar(
|
||||
isScrollable: true,
|
||||
tabAlignment: TabAlignment.start,
|
||||
tabs: loadingState.response!
|
||||
.map((e) => Tab(text: e.name ?? ''))
|
||||
.toList(),
|
||||
),
|
||||
Expanded(
|
||||
child: tabBarView(
|
||||
children: loadingState.response!
|
||||
.map((e) => LiveAreaChildPage(
|
||||
areaId: e.id,
|
||||
parentAreaId: e.parentId,
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: LiveAreaChildPage(
|
||||
areaId: widget.areaId,
|
||||
parentAreaId: widget.parentAreaId,
|
||||
),
|
||||
Error() => LiveAreaChildPage(
|
||||
areaId: widget.areaId,
|
||||
parentAreaId: widget.parentAreaId,
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user