Merge branch 'feature-replySave'

This commit is contained in:
guozhigq
2024-08-11 23:49:27 +08:00
2 changed files with 204 additions and 13 deletions

View File

@ -16,11 +16,14 @@ import 'package:pilipala/pages/main/index.dart';
import 'package:pilipala/pages/video/detail/index.dart';
import 'package:pilipala/pages/video/detail/reply_new/index.dart';
import 'package:pilipala/plugin/pl_gallery/index.dart';
import 'package:pilipala/plugin/pl_popup/index.dart';
import 'package:pilipala/utils/app_scheme.dart';
import 'package:pilipala/utils/feed_back.dart';
import 'package:pilipala/utils/id_utils.dart';
import 'package:pilipala/utils/storage.dart';
import 'package:pilipala/utils/url_utils.dart';
import 'package:pilipala/utils/utils.dart';
import 'reply_save.dart';
import 'zan.dart';
Box setting = GStrorage.setting;
@ -33,6 +36,7 @@ class ReplyItem extends StatelessWidget {
this.showReplyRow = true,
this.replyReply,
this.replyType,
this.replySave = false,
super.key,
});
final ReplyItemModel? replyItem;
@ -41,6 +45,7 @@ class ReplyItem extends StatelessWidget {
final bool? showReplyRow;
final Function? replyReply;
final ReplyType? replyType;
final bool? replySave;
@override
Widget build(BuildContext context) {
@ -48,19 +53,28 @@ class ReplyItem extends StatelessWidget {
child: InkWell(
// 点击整个评论区 评论详情/回复
onTap: () {
if (replySave!) {
return;
}
feedBack();
if (replyReply != null) {
replyReply!(replyItem, null, replyItem!.replies!.isNotEmpty);
}
},
onLongPress: () {
if (replySave!) {
return;
}
feedBack();
showModalBottomSheet(
context: context,
useRootNavigator: true,
isScrollControlled: true,
builder: (context) {
return MorePanel(item: replyItem);
return MorePanel(
item: replyItem,
mainFloor: true,
);
},
);
},
@ -233,7 +247,7 @@ class ReplyItem extends StatelessWidget {
),
),
// 操作区域
bottonAction(context, replyItem!.replyControl),
bottonAction(context, replyItem!.replyControl, replySave),
// 一楼的评论
if ((replyItem!.replyControl!.isShow! ||
replyItem!.replies!.isNotEmpty) &&
@ -254,7 +268,7 @@ class ReplyItem extends StatelessWidget {
}
// 感谢、回复、复制
Widget bottonAction(BuildContext context, replyControl) {
Widget bottonAction(BuildContext context, replyControl, replySave) {
ColorScheme colorScheme = Theme.of(context).colorScheme;
TextTheme textTheme = Theme.of(context).textTheme;
return Row(
@ -287,16 +301,26 @@ class ReplyItem extends StatelessWidget {
});
},
child: Row(children: [
Icon(Icons.reply,
size: 18, color: colorScheme.outline.withOpacity(0.8)),
const SizedBox(width: 3),
Text(
'回复',
style: TextStyle(
fontSize: textTheme.labelMedium!.fontSize,
color: colorScheme.outline,
if (!replySave!) ...[
Icon(Icons.reply,
size: 18, color: colorScheme.outline.withOpacity(0.8)),
const SizedBox(width: 3),
Text(
'回复',
style: TextStyle(
fontSize: textTheme.labelMedium!.fontSize,
color: colorScheme.outline,
),
)
],
if (replySave!)
Text(
IdUtils.av2bv(replyItem!.oid!),
style: TextStyle(
fontSize: textTheme.labelMedium!.fontSize,
color: colorScheme.outline,
),
),
),
]),
),
),
@ -1008,7 +1032,12 @@ InlineSpan buildContent(
class MorePanel extends StatelessWidget {
final dynamic item;
const MorePanel({super.key, required this.item});
final bool mainFloor;
const MorePanel({
super.key,
required this.item,
this.mainFloor = false,
});
Future<dynamic> menuActionHandler(String type) async {
String message = item.content.message ?? item.content;
@ -1030,6 +1059,13 @@ class MorePanel extends StatelessWidget {
},
);
break;
case 'save':
Get.back();
Navigator.push(
Get.context!,
PlPopupRoute(child: ReplySave(replyItem: item)),
);
break;
// case 'block':
// SmartDialog.showToast('加入黑名单');
// break;
@ -1080,6 +1116,13 @@ class MorePanel extends StatelessWidget {
leading: const Icon(Icons.copy_outlined, size: 19),
title: Text('自由复制', style: textTheme.titleSmall),
),
if (mainFloor && item.content.pictures.isEmpty)
ListTile(
onTap: () async => await menuActionHandler('save'),
minLeadingWidth: 0,
leading: const Icon(Icons.save_alt_rounded, size: 19),
title: Text('本地保存', style: textTheme.titleSmall),
),
// ListTile(
// onTap: () async => await menuActionHandler('block'),
// minLeadingWidth: 0,

View File

@ -0,0 +1,148 @@
import 'dart:math';
import 'dart:typed_data';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:pilipala/models/video/reply/item.dart';
import 'package:pilipala/pages/video/detail/reply/widgets/reply_item.dart';
import 'package:saver_gallery/saver_gallery.dart';
class ReplySave extends StatefulWidget {
final ReplyItemModel? replyItem;
const ReplySave({required this.replyItem, super.key});
@override
State<ReplySave> createState() => _ReplySaveState();
}
class _ReplySaveState extends State<ReplySave> {
final _boundaryKey = GlobalKey();
void _generatePicWidget() async {
SmartDialog.showLoading(msg: '保存中');
try {
RenderRepaintBoundary boundary = _boundaryKey.currentContext!
.findRenderObject() as RenderRepaintBoundary;
var image = await boundary.toImage(pixelRatio: 3);
ByteData? byteData = await image.toByteData(format: ImageByteFormat.png);
Uint8List pngBytes = byteData!.buffer.asUint8List();
String picName =
"plpl_reply_${DateTime.now().toString().replaceAll(RegExp(r'[- :]'), '').split('.').first}";
final result = await SaverGallery.saveImage(
Uint8List.fromList(pngBytes),
name: '$picName.png',
androidRelativePath: "Pictures/PiliPala",
androidExistNotSave: false,
);
if (result.isSuccess) {
SmartDialog.showToast('保存成功');
}
} catch (err) {
print(err);
} finally {
SmartDialog.dismiss();
}
}
List<Widget> _createWidgets(int count, Widget Function() builder) {
return List<Widget>.generate(count, (_) => Expanded(child: builder()));
}
List<Widget> _createColumnWidgets() {
return _createWidgets(3, () => Row(children: _createRowWidgets()));
}
List<Widget> _createRowWidgets() {
return _createWidgets(
4,
() => Center(
child: Transform.rotate(
angle: pi / 10,
child: const Text(
'PiliPala',
style: TextStyle(
color: Color(0x08000000),
fontSize: 18,
fontWeight: FontWeight.bold,
decoration: TextDecoration.none,
),
),
),
),
);
}
@override
Widget build(BuildContext context) {
return SafeArea(
top: false,
bottom: false,
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 4.0, sigmaY: 4.0),
child: Container(
width: Get.width,
height: Get.height,
padding: EdgeInsets.fromLTRB(
0,
MediaQuery.of(context).padding.top + 4,
0,
MediaQuery.of(context).padding.bottom + 4,
),
color: Colors.black54,
child: Column(
children: [
Expanded(
child: Container(
clipBehavior: Clip.antiAlias,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
),
child: Center(
child: SingleChildScrollView(
child: RepaintBoundary(
key: _boundaryKey,
child: IntrinsicHeight(
child: Stack(
children: [
ReplyItem(
replyItem: widget.replyItem,
showReplyRow: false,
replySave: true,
),
Positioned.fill(
child: Column(
children: _createColumnWidgets(),
),
),
],
),
),
),
),
),
),
),
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
FilledButton(
onPressed: () => Get.back(),
child: const Text('取消'),
),
const SizedBox(width: 40),
FilledButton(
onPressed: _generatePicWidget,
child: const Text('保存'),
),
],
),
],
),
),
),
);
}
}