Merge branch 'main' into feature-m3Design

This commit is contained in:
guozhigq
2023-07-23 21:14:25 +08:00
13 changed files with 401 additions and 273 deletions

View File

@ -5,6 +5,7 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:pilipala/http/reply.dart';
import 'package:pilipala/http/video.dart';
import 'package:pilipala/models/common/reply_sort_type.dart';
import 'package:pilipala/models/common/reply_type.dart';
import 'package:pilipala/models/video/reply/data.dart';
import 'package:pilipala/models/video/reply/item.dart';
@ -27,7 +28,6 @@ class VideoReplyController extends GetxController {
int currentPage = 0;
bool isLoadingMore = false;
RxString noMore = ''.obs;
RxBool autoFocus = false.obs;
// 当前回复的回复
ReplyItemModel? currentReplyItem;
// 回复来源
@ -37,11 +37,19 @@ class VideoReplyController extends GetxController {
// 默认回复主楼
String replyLevel = '0';
ReplySortType sortType = ReplySortType.time;
RxString sortTypeTitle = ReplySortType.time.titles.obs;
RxString sortTypeLabel = ReplySortType.time.labels.obs;
Future queryReplyList({type = 'init'}) async {
isLoadingMore = true;
var res = level == '1'
? await ReplyHttp.replyList(
oid: aid!, pageNum: currentPage + 1, type: 1)
oid: aid!,
pageNum: currentPage + 1,
type: ReplyType.video.index,
sort: sortType.index,
)
: await ReplyHttp.replyReplyList(
oid: aid!, root: rpid!, pageNum: currentPage + 1, type: 1);
if (res['status']) {
@ -91,33 +99,24 @@ class VideoReplyController extends GetxController {
queryReplyList(type: 'onLoad');
}
wakeUpReply() {
autoFocus.value = true;
}
// 发表评论
Future submitReplyAdd() async {
var result = await VideoHttp.replyAdd(
type: ReplyType.video,
oid: aid!,
root: replyLevel == '0'
? 0
: replyLevel == '1'
? currentReplyItem!.rpid
: rPid,
parent: replyLevel == '0'
? 0
: replyLevel == '1'
? currentReplyItem!.rpid
: currentReplyItem!.rpid,
message: replyLevel == '2'
? ' 回复 @${currentReplyItem!.member!.uname!} : 2楼31'
: '2楼31',
);
if (result['status']) {
SmartDialog.showToast(result['data']['success_toast']);
} else {
SmartDialog.showToast(result['message']);
// 排序搜索评论
queryBySort() {
switch (sortType) {
case ReplySortType.time:
sortType = ReplySortType.like;
break;
case ReplySortType.like:
sortType = ReplySortType.reply;
break;
case ReplySortType.reply:
sortType = ReplySortType.time;
break;
default:
}
sortTypeTitle.value = sortType.titles;
sortTypeLabel.value = sortType.labels;
currentPage = 0;
replyList.clear();
queryReplyList(type: 'init');
}
}

View File

@ -34,7 +34,6 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
late VideoReplyController _videoReplyController;
late AnimationController fabAnimationCtr;
// List<ReplyItemModel>? replyList;
Future? _futureBuilderFuture;
bool _isFabVisible = true;
String replyLevel = '1';
@ -112,15 +111,15 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
_videoReplyController.replyLevel = '0';
}
await Future.delayed(const Duration(microseconds: 100));
_videoReplyController.wakeUpReply();
// await Future.delayed(const Duration(microseconds: 100));
// _videoReplyController.wakeUpReply();
}
// 展示二级回复
void replyReply(replyItem) {
VideoDetailController videoDetailCtr =
Get.find<VideoDetailController>(tag: Get.arguments['heroTag']);
videoDetailCtr.oid = replyItem.replies!.first.oid;
videoDetailCtr.oid = replyItem.oid;
videoDetailCtr.fRpid = replyItem.rpid!;
videoDetailCtr.firstFloor = replyItem;
videoDetailCtr.showReplyReplyPanel();
@ -147,7 +146,46 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
controller: _videoReplyController.scrollController,
key: const PageStorageKey<String>('评论'),
slivers: <Widget>[
const SliverToBoxAdapter(child: SizedBox(height: 12)),
SliverPersistentHeader(
pinned: false,
floating: true,
delegate: _MySliverPersistentHeaderDelegate(
child: Container(
color: Theme.of(context).colorScheme.background,
padding: const EdgeInsets.fromLTRB(12, 6, 10, 6),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Obx(
() => AnimatedSwitcher(
duration: const Duration(milliseconds: 400),
transitionBuilder:
(Widget child, Animation<double> animation) {
return ScaleTransition(
scale: animation, child: child);
},
child: Text(
_videoReplyController.sortTypeTitle.value,
key: ValueKey<String>(
_videoReplyController.sortTypeTitle.value),
),
),
),
SizedBox(
height: 35,
child: TextButton.icon(
onPressed: () =>
_videoReplyController.queryBySort(),
icon: const Icon(Icons.sort, size: 17),
label: Obx(() => Text(
_videoReplyController.sortTypeLabel.value)),
),
)
],
),
),
),
),
FutureBuilder(
future: _futureBuilderFuture,
builder: (context, snapshot) {
@ -156,40 +194,51 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
if (data['status']) {
// 请求成功
return Obx(
() => SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
if (index ==
_videoReplyController.replyList.length) {
return Container(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context)
.padding
.bottom),
height:
MediaQuery.of(context).padding.bottom +
100,
child: Center(
child: Obx(() => Text(
_videoReplyController.noMore.value)),
),
);
} else {
return ReplyItem(
replyItem:
_videoReplyController.replyList[index],
showReplyRow: true,
replyLevel: replyLevel,
replyReply: (replyItem) =>
replyReply(replyItem),
replyType: ReplyType.video,
);
}
},
childCount:
_videoReplyController.replyList.length + 1,
),
),
() => _videoReplyController.replyList.isEmpty
? SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
return const VideoReplySkeleton();
}, childCount: 5),
)
: SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
if (index ==
_videoReplyController
.replyList.length) {
return Container(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context)
.padding
.bottom),
height: MediaQuery.of(context)
.padding
.bottom +
100,
child: Center(
child: Obx(() => Text(
_videoReplyController
.noMore.value)),
),
);
} else {
return ReplyItem(
replyItem: _videoReplyController
.replyList[index],
showReplyRow: true,
replyLevel: replyLevel,
replyReply: (replyItem) =>
replyReply(replyItem),
replyType: ReplyType.video,
);
}
},
childCount:
_videoReplyController.replyList.length +
1,
),
),
);
} else {
// 请求错误
@ -231,7 +280,6 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
isScrollControlled: true,
builder: (BuildContext context) {
return VideoReplyNewDialog(
replyLevel: '0',
oid: IdUtils.bv2av(Get.parameters['bvid']!),
root: 0,
parent: 0,
@ -256,3 +304,33 @@ class _VideoReplyPanelState extends State<VideoReplyPanel>
);
}
}
class _MySliverPersistentHeaderDelegate extends SliverPersistentHeaderDelegate {
final double _minExtent = 45;
final double _maxExtent = 45;
final Widget child;
_MySliverPersistentHeaderDelegate({required this.child});
@override
Widget build(
BuildContext context, double shrinkOffset, bool overlapsContent) {
//创建child子组件
//shrinkOffsetchild偏移值minExtent~maxExtent
//overlapsContentSliverPersistentHeader覆盖其他子组件返回true否则返回false
return child;
}
//SliverPersistentHeader最大高度
@override
double get maxExtent => _maxExtent;
//SliverPersistentHeader最小高度
@override
double get minExtent => _minExtent;
@override
bool shouldRebuild(covariant _MySliverPersistentHeaderDelegate oldDelegate) {
return true;
}
}

View File

@ -1,17 +1,12 @@
import 'dart:developer';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_meedu_media_kit/meedu_player.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart';
import 'package:pilipala/common/widgets/network_img_layer.dart';
import 'package:pilipala/models/common/reply_type.dart';
import 'package:pilipala/models/video/reply/item.dart';
import 'package:pilipala/pages/video/detail/controller.dart';
import 'package:pilipala/pages/video/detail/reply/index.dart';
import 'package:pilipala/pages/video/detail/replyNew/index.dart';
import 'package:pilipala/pages/video/detail/replyReply/index.dart';
import 'package:pilipala/utils/utils.dart';
class ReplyItem extends StatelessWidget {
@ -33,66 +28,52 @@ class ReplyItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
return InkWell(
onTap: () {},
child: Column(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(12, 4, 8, 2),
child: content(context),
),
// Divider(
// height: 1,
// indent: 52,
// endIndent: 10,
// color: Theme.of(context).dividerColor.withOpacity(0.08),
// )
],
return Material(
child: InkWell(
// 点击整个评论区 评论详情/回复
onTap: () => replyReply!(replyItem),
child: Padding(
padding: const EdgeInsets.fromLTRB(12, 4, 8, 2),
child: content(context),
),
),
);
}
Widget lfAvtar(context, heroTag) {
return Container(
margin: const EdgeInsets.only(top: 5),
child: Stack(
children: [
Hero(
tag: heroTag,
child: NetworkImgLayer(
src: replyItem!.member!.avatar,
width: 34,
height: 34,
type: 'avatar',
),
margin: const EdgeInsets.only(top: 5),
child: Stack(
children: [
Hero(
tag: heroTag,
child: NetworkImgLayer(
src: replyItem!.member!.avatar,
width: 34,
height: 34,
type: 'avatar',
),
if (replyItem!.member!.officialVerify != null &&
replyItem!.member!.officialVerify!['type'] == 0)
Positioned(
right: 0,
bottom: 0,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(7),
color: Theme.of(context).colorScheme.background,
),
child: Icon(
Icons.offline_bolt,
color: Theme.of(context).colorScheme.primary,
size: 16,
),
),
if (replyItem!.member!.officialVerify != null &&
replyItem!.member!.officialVerify!['type'] == 0)
Positioned(
right: 0,
bottom: 0,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(7),
color: Theme.of(context).colorScheme.background,
),
child: Icon(
Icons.offline_bolt,
color: Theme.of(context).colorScheme.primary,
size: 16,
),
),
],
)
// child:
// NetworkImgLayer(
// src: replyItem!.member!.avatar,
// width: 30,
// height: 30,
// type: 'avatar',
// ),
);
),
],
),
);
}
Widget content(context) {
@ -122,7 +103,7 @@ class ReplyItem extends StatelessWidget {
replyItem!.member!.uname!,
style: TextStyle(
color: replyItem!.isUp! ||
replyItem!.member!.vip!['vipType'] > 0
replyItem!.member!.vip!['vipStatus'] > 0
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.outline,
fontSize:
@ -196,15 +177,15 @@ class ReplyItem extends StatelessWidget {
focusNode: FocusNode(),
selectionControls: MaterialTextSelectionControls(),
child: Text.rich(
style: const TextStyle(height: 1.65),
style: const TextStyle(height: 1.75),
maxLines:
replyItem!.content!.isText! && replyLevel == '1' ? 6 : 999,
replyItem!.content!.isText! && replyLevel == '1' ? 3 : 999,
overflow: TextOverflow.ellipsis,
TextSpan(
children: [
if (replyItem!.isTop!)
WidgetSpan(child: UpTag(tagText: 'TOP')),
buildContent(context, replyItem!, replyReply),
buildContent(context, replyItem!, replyReply, null),
],
),
),
@ -212,10 +193,12 @@ class ReplyItem extends StatelessWidget {
),
// 操作区域
bottonAction(context, replyItem!.replyControl),
const SizedBox(height: 3),
if (replyItem!.replies!.isNotEmpty && showReplyRow!) ...[
// 一楼的评论
if ((replyItem!.replyControl!.isShow! ||
replyItem!.replies!.isNotEmpty) &&
showReplyRow!) ...[
Padding(
padding: const EdgeInsets.only(top: 2, bottom: 12),
padding: const EdgeInsets.only(top: 5, bottom: 12),
child: ReplyItemRow(
replies: replyItem!.replies,
replyControl: replyItem!.replyControl,
@ -281,16 +264,16 @@ class ReplyItem extends StatelessWidget {
isScrollControlled: true,
builder: (builder) {
return VideoReplyNewDialog(
replyLevel: replyLevel,
oid: replyItem!.oid,
root: replyItem!.rpid,
parent: replyItem!.rpid,
replyType: replyType,
replyItem: replyItem,
);
},
).then((value) => {
// 完成评论,数据添加
if (value['data'] != null)
if (value != null && value['data'] != null)
{
addReply!(value['data'])
// replyControl.replies.add(value['data']),
@ -358,58 +341,60 @@ class ReplyItemRow extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
for (var i = 0; i < replies!.length; i++) ...[
InkWell(
onTap: () => replyReply!(replyItem),
child: Container(
width: double.infinity,
padding: EdgeInsets.fromLTRB(
8,
i == 0 && (extraRow == 1 || replies!.length > 1) ? 8 : 5,
8,
i == 0 && (extraRow == 1 || replies!.length > 1) ? 5 : 6,
),
child: Text.rich(
overflow: extraRow == 1
? TextOverflow.ellipsis
: TextOverflow.visible,
maxLines: extraRow == 1 ? 2 : null,
TextSpan(
children: [
TextSpan(
text: replies![i].member.uname + ' ',
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.titleSmall!
.fontSize,
color: Theme.of(context).colorScheme.primary,
if (replies!.isNotEmpty)
for (var i = 0; i < replies!.length; i++) ...[
InkWell(
// 一楼点击评论展开评论详情
onTap: () => replyReply!(replyItem),
child: Container(
width: double.infinity,
padding: EdgeInsets.fromLTRB(
8,
i == 0 && (extraRow == 1 || replies!.length > 1) ? 8 : 5,
8,
i == 0 && (extraRow == 1 || replies!.length > 1) ? 5 : 6,
),
child: Text.rich(
overflow: TextOverflow.ellipsis,
maxLines: 2,
TextSpan(
children: [
TextSpan(
text: replies![i].member.uname + ' ',
style: TextStyle(
fontSize: Theme.of(context)
.textTheme
.titleSmall!
.fontSize,
color: Theme.of(context).colorScheme.primary,
),
recognizer: TapGestureRecognizer()
..onTap = () {
String heroTag =
Utils.makeHeroTag(replies![i].member.mid);
Get.toNamed(
'/member?mid=${replies![i].member.mid}',
arguments: {
'face': replies![i].member.avatar,
'heroTag': heroTag
});
},
),
recognizer: TapGestureRecognizer()
..onTap = () {
String heroTag =
Utils.makeHeroTag(replies![i].member.mid);
Get.toNamed(
'/member?mid=${replies![i].member.mid}',
arguments: {
'face': replies![i].member.avatar,
'heroTag': heroTag
});
},
),
if (replies![i].isUp)
WidgetSpan(
child: UpTag(),
),
buildContent(context, replies![i], replyReply),
],
if (replies![i].isUp)
WidgetSpan(
child: UpTag(),
),
buildContent(
context, replies![i], replyReply, replyItem),
],
),
),
),
),
)
],
)
],
if (extraRow == 1)
InkWell(
// 一楼点击【共xx条回复】展开评论详情
onTap: () => replyReply!(replyItem),
child: Container(
width: double.infinity,
@ -441,7 +426,11 @@ class ReplyItemRow extends StatelessWidget {
}
}
InlineSpan buildContent(BuildContext context, replyItem, replyReply) {
InlineSpan buildContent(
BuildContext context, replyItem, replyReply, fReplyItem) {
// replyItem 当前回复内容
// replyReply 查看二楼回复(回复详情)回调
// fReplyItem 父级回复内容,用作二楼回复(回复详情)展示
var content = replyItem.content;
if (content.emote.isEmpty &&
content.atNameToMid.isEmpty &&
@ -450,7 +439,9 @@ InlineSpan buildContent(BuildContext context, replyItem, replyReply) {
content.pictures.isEmpty) {
return TextSpan(
text: content.message,
recognizer: TapGestureRecognizer()..onTap = () => replyReply(replyItem),
recognizer: TapGestureRecognizer()
..onTap =
() => replyReply(replyItem.root == 0 ? replyItem : fReplyItem),
);
}
List<InlineSpan> spanChilds = [];
@ -510,11 +501,19 @@ InlineSpan buildContent(BuildContext context, replyItem, replyReply) {
),
);
} else {
spanChilds.add(TextSpan(text: matchStr));
spanChilds.add(TextSpan(
text: matchStr,
recognizer: TapGestureRecognizer()
..onTap = () =>
replyReply(replyItem.root == 0 ? replyItem : fReplyItem)));
return matchStr;
}
} else {
spanChilds.add(TextSpan(text: matchStr));
spanChilds.add(TextSpan(
text: matchStr,
recognizer: TapGestureRecognizer()
..onTap = () =>
replyReply(replyItem.root == 0 ? replyItem : fReplyItem)));
return matchStr;
}
return '';
@ -595,7 +594,11 @@ InlineSpan buildContent(BuildContext context, replyItem, replyReply) {
return '';
},
onNonMatch: (String str) {
spanChilds.add(TextSpan(text: str));
spanChilds.add(TextSpan(
text: str,
recognizer: TapGestureRecognizer()
..onTap = () => replyReply(
replyItem.root == 0 ? replyItem : fReplyItem)));
return str;
},
);
@ -628,7 +631,11 @@ InlineSpan buildContent(BuildContext context, replyItem, replyReply) {
);
if (content.atNameToMid.isEmpty && content.jumpUrl.isEmpty) {
spanChilds.add(TextSpan(text: str));
spanChilds.add(TextSpan(
text: str,
recognizer: TapGestureRecognizer()
..onTap = () =>
replyReply(replyItem.root == 0 ? replyItem : fReplyItem)));
}
return str;
},

View File

@ -12,16 +12,16 @@ import 'package:pilipala/utils/storage.dart';
class VideoReplyNewDialog extends StatefulWidget {
int? oid;
int? root;
String? replyLevel;
int? parent;
ReplyType? replyType;
ReplyItemModel? replyItem;
VideoReplyNewDialog({
this.oid,
this.root,
this.replyLevel,
this.parent,
this.replyType,
this.replyItem,
});
@override
@ -36,14 +36,12 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
double _keyboardHeight = 0.0; // 键盘高度
final _debouncer = Debouncer(milliseconds: 100); // 设置延迟时间
bool ableClean = false;
bool autoFocus = false;
Timer? timer;
Box localCache = GStrorage.localCache;
late double sheetHeight;
@override
void initState() {
// TODO: implement initState
super.initState();
// 监听输入框聚焦
// replyContentFocusNode.addListener(_onFocus);
@ -74,14 +72,18 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
oid: widget.oid!,
root: widget.root!,
parent: widget.parent!,
message: message,
message: widget.replyItem != null && widget.replyItem!.root != 0
? ' 回复 @${widget.replyItem!.member!.uname!} : $message'
: message,
);
if (result['status']) {
SmartDialog.showToast(result['data']['success_toast']);
Get.back(result: {
'data': ReplyItemModel.fromJson(result['data']['reply'], ''),
});
} else {}
} else {
SmartDialog.showToast(result['msg']);
}
}
@override
@ -103,6 +105,12 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
});
}
@override
void dispose() {
_replyContentController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Container(

View File

@ -123,7 +123,7 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
addReply: (replyItem) {
_videoReplyReplyController.replyList.add(replyItem);
},
replyType: ReplyType.video,
replyType: widget.replyType,
),
),
SliverToBoxAdapter(
@ -167,16 +167,16 @@ class _VideoReplyReplyPanelState extends State<VideoReplyReplyPanel> {
),
);
} else {
return Material(
child: ReplyItem(
replyItem: _videoReplyReplyController
.replyList[index],
replyLevel: '2',
showReplyRow: false,
addReply: (replyItem) {
_videoReplyReplyController.replyList
.add(replyItem);
}),
return ReplyItem(
replyItem: _videoReplyReplyController
.replyList[index],
replyLevel: '2',
showReplyRow: false,
addReply: (replyItem) {
_videoReplyReplyController.replyList
.add(replyItem);
},
replyType: widget.replyType,
);
}
},