mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: space opus
Closes #833 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
59
lib/pages/member_opus/controller.dart
Normal file
59
lib/pages/member_opus/controller.dart
Normal file
@@ -0,0 +1,59 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/member.dart';
|
||||
import 'package:PiliPlus/models/space/filter.dart';
|
||||
import 'package:PiliPlus/models/space_opus/data.dart';
|
||||
import 'package:PiliPlus/models/space_opus/item.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:PiliPlus/pages/member/controller.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class MemberOpusController
|
||||
extends CommonListController<SpaceOpusData, SpaceOpusItemModel> {
|
||||
MemberOpusController({
|
||||
required this.heroTag,
|
||||
required this.mid,
|
||||
});
|
||||
|
||||
final String? heroTag;
|
||||
final int mid;
|
||||
|
||||
String offset = '';
|
||||
Rx<SpaceTabFilter> type =
|
||||
SpaceTabFilter(text: "全部图文", meta: "all", tabName: "图文").obs;
|
||||
List<SpaceTabFilter>? filter;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
filter = Get.find<MemberController>(tag: heroTag)
|
||||
.tab2
|
||||
?.firstWhereOrNull((e) => e.param == 'contribute')
|
||||
?.items
|
||||
?.firstWhereOrNull((e) => e.param == 'opus')
|
||||
?.filter;
|
||||
queryData();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> onRefresh() {
|
||||
offset = '';
|
||||
return super.onRefresh();
|
||||
}
|
||||
|
||||
@override
|
||||
List<SpaceOpusItemModel>? getDataList(SpaceOpusData response) {
|
||||
offset = response.offset ?? '';
|
||||
if (response.hasMore == false) {
|
||||
isEnd = true;
|
||||
}
|
||||
return response.items;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<SpaceOpusData>> customGetData() => MemberHttp.spaceOpus(
|
||||
hostMid: mid,
|
||||
page: currentPage,
|
||||
offset: offset,
|
||||
type: type.value.meta,
|
||||
);
|
||||
}
|
||||
154
lib/pages/member_opus/view.dart
Normal file
154
lib/pages/member_opus/view.dart
Normal file
@@ -0,0 +1,154 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/skeleton/space_opus.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/space_opus/item.dart';
|
||||
import 'package:PiliPlus/pages/member_opus/controller.dart';
|
||||
import 'package:PiliPlus/pages/member_opus/widgets/space_opus_item.dart';
|
||||
import 'package:PiliPlus/utils/grid.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:waterfall_flow/waterfall_flow.dart';
|
||||
|
||||
class MemberOpus extends StatefulWidget {
|
||||
const MemberOpus({
|
||||
super.key,
|
||||
required this.heroTag,
|
||||
required this.mid,
|
||||
});
|
||||
|
||||
final String? heroTag;
|
||||
final int mid;
|
||||
|
||||
@override
|
||||
State<MemberOpus> createState() => _MemberOpusState();
|
||||
}
|
||||
|
||||
class _MemberOpusState extends State<MemberOpus>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
late final _controller = Get.put(
|
||||
MemberOpusController(
|
||||
mid: widget.mid,
|
||||
heroTag: widget.heroTag,
|
||||
),
|
||||
tag: widget.heroTag,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Stack(
|
||||
children: [
|
||||
refreshIndicator(
|
||||
onRefresh: _controller.onRefresh,
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
left: StyleString.safeSpace,
|
||||
right: StyleString.safeSpace,
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 90,
|
||||
),
|
||||
sliver: Obx(() => _buildBody(_controller.loadingState.value)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (_controller.filter?.isNotEmpty == true)
|
||||
Positioned(
|
||||
right: 16,
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 16,
|
||||
child: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 12),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: _controller.filter!
|
||||
.map(
|
||||
(e) => ListTile(
|
||||
onTap: () {
|
||||
if (e == _controller.type.value) {
|
||||
return;
|
||||
}
|
||||
Get.back();
|
||||
_controller
|
||||
..type.value = e
|
||||
..onReload();
|
||||
},
|
||||
tileColor: e == _controller.type.value
|
||||
? Theme.of(context)
|
||||
.colorScheme
|
||||
.onInverseSurface
|
||||
: null,
|
||||
dense: true,
|
||||
title: Text(
|
||||
e.text ?? e.tabName!,
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
label: Row(
|
||||
children: [
|
||||
const Icon(size: 20, Icons.sort),
|
||||
Obx(
|
||||
() => Text(_controller.type.value.text ??
|
||||
_controller.type.value.tabName!),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState<List<SpaceOpusItemModel>?> loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => SliverWaterfallFlow.extent(
|
||||
maxCrossAxisExtent: Grid.smallCardWidth,
|
||||
mainAxisSpacing: StyleString.safeSpace,
|
||||
crossAxisSpacing: StyleString.safeSpace,
|
||||
children: List.generate(10, (_) => const SpaceOpusSkeleton()),
|
||||
),
|
||||
Success() => loadingState.response?.isNotEmpty == true
|
||||
? SliverWaterfallFlow.extent(
|
||||
maxCrossAxisExtent: Grid.smallCardWidth,
|
||||
mainAxisSpacing: StyleString.safeSpace,
|
||||
crossAxisSpacing: StyleString.safeSpace,
|
||||
lastChildLayoutTypeBuilder: (index) {
|
||||
if (index == loadingState.response!.length - 1) {
|
||||
_controller.onLoadMore();
|
||||
}
|
||||
return index == loadingState.response!.length
|
||||
? LastChildLayoutType.foot
|
||||
: LastChildLayoutType.none;
|
||||
},
|
||||
children: loadingState.response!
|
||||
.map((item) => SpaceOpusItem(item: item))
|
||||
.toList(),
|
||||
)
|
||||
: HttpError(
|
||||
onReload: _controller.onReload,
|
||||
),
|
||||
Error() => HttpError(
|
||||
errMsg: loadingState.errMsg,
|
||||
onReload: _controller.onReload,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
95
lib/pages/member_opus/widgets/space_opus_item.dart
Normal file
95
lib/pages/member_opus/widgets/space_opus_item.dart
Normal file
@@ -0,0 +1,95 @@
|
||||
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
||||
import 'package:PiliPlus/common/widgets/stat/stat.dart';
|
||||
import 'package:PiliPlus/models/space_opus/item.dart';
|
||||
import 'package:PiliPlus/utils/page_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class SpaceOpusItem extends StatelessWidget {
|
||||
const SpaceOpusItem({
|
||||
super.key,
|
||||
required this.item,
|
||||
});
|
||||
|
||||
final SpaceOpusItemModel item;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final hasPic = item.cover?.url?.isNotEmpty == true;
|
||||
return Card(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
margin: EdgeInsets.zero,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(6)),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
PageUtils.pushDynFromId(id: item.opusId!);
|
||||
},
|
||||
borderRadius: const BorderRadius.all(Radius.circular(6)),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (hasPic)
|
||||
Stack(
|
||||
children: [
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
return NetworkImgLayer(
|
||||
width: constraints.maxWidth,
|
||||
height: constraints.maxWidth * item.cover!.ratio,
|
||||
src: item.cover!.url,
|
||||
type: 'emote',
|
||||
quality: 60,
|
||||
);
|
||||
},
|
||||
),
|
||||
Positioned(
|
||||
left: 0,
|
||||
bottom: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
height: 45,
|
||||
alignment: Alignment.bottomLeft,
|
||||
padding: const EdgeInsets.only(left: 8, bottom: 4),
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [Colors.transparent, Colors.black54],
|
||||
),
|
||||
),
|
||||
child: StatView(
|
||||
context: context,
|
||||
value: item.stat?.like ?? 0,
|
||||
goto: 'like',
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (item.content?.isNotEmpty == true)
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 8, vertical: 10),
|
||||
child: Text(
|
||||
item.content!,
|
||||
maxLines: hasPic ? 4 : 6,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
if (!hasPic)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8, bottom: 8, right: 8),
|
||||
child: StatView(
|
||||
context: context,
|
||||
value: item.stat?.like ?? 0,
|
||||
goto: 'like',
|
||||
textColor: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user