🐛 Fix share

This commit is contained in:
LittleSheep 2024-07-27 14:32:31 +08:00
parent 6ca4aad1c4
commit 74b6ccd5c7
2 changed files with 21 additions and 16 deletions

View File

@ -25,7 +25,7 @@ class _PostActionState extends State<PostAction> {
bool _isBusy = true; bool _isBusy = true;
bool _canModifyContent = false; bool _canModifyContent = false;
void checkAbleToModifyContent() async { void _checkAbleToModifyContent() async {
final AuthProvider auth = Get.find(); final AuthProvider auth = Get.find();
if (auth.isAuthorized.isFalse) return; if (auth.isAuthorized.isFalse) return;
@ -38,10 +38,25 @@ class _PostActionState extends State<PostAction> {
}); });
} }
Future<void> _doShare() async {
final box = context.findRenderObject() as RenderBox?;
await Share.share(
'postShareContent'.trParams({
'username': widget.item.author.nick,
'content': widget.item.body['content'] ?? 'no content',
'link': 'https://sn.solsynth.dev/posts/${widget.item.id}',
}),
subject: 'postShareSubject'.trParams({
'username': widget.item.author.nick,
}),
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
);
}
@override @override
void initState() { void initState() {
super.initState(); super.initState();
checkAbleToModifyContent(); _checkAbleToModifyContent();
} }
@override @override
@ -72,17 +87,7 @@ class _PostActionState extends State<PostAction> {
leading: const Icon(Icons.share), leading: const Icon(Icons.share),
title: Text('share'.tr), title: Text('share'.tr),
onTap: () async { onTap: () async {
await Share.share( await _doShare();
'postShareContent'.trParams({
'username': widget.item.author.nick,
'content': widget.item.body['text'],
'link':
'https://sn.solsynth.dev/posts/${widget.item.id}',
}),
subject: 'postShareSubject'.trParams({
'username': widget.item.author.nick,
}),
);
Navigator.pop(context); Navigator.pop(context);
}, },
), ),
@ -187,7 +192,7 @@ class PostDeletionDialog extends StatefulWidget {
class _PostDeletionDialogState extends State<PostDeletionDialog> { class _PostDeletionDialogState extends State<PostDeletionDialog> {
bool _isBusy = false; bool _isBusy = false;
void performAction() async { void _performAction() async {
final AuthProvider auth = Get.find(); final AuthProvider auth = Get.find();
if (auth.isAuthorized.isFalse) return; if (auth.isAuthorized.isFalse) return;
@ -219,7 +224,7 @@ class _PostDeletionDialogState extends State<PostDeletionDialog> {
child: Text('cancel'.tr), child: Text('cancel'.tr),
), ),
TextButton( TextButton(
onPressed: _isBusy ? null : () => performAction(), onPressed: _isBusy ? null : () => _performAction(),
child: Text('confirm'.tr), child: Text('confirm'.tr),
), ),
], ],

View File

@ -2,7 +2,7 @@ name: solian
description: "The Solar Network App" description: "The Solar Network App"
publish_to: "none" publish_to: "none"
version: 1.1.0+47 version: 1.1.0+48
environment: environment:
sdk: ">=3.3.4 <4.0.0" sdk: ">=3.3.4 <4.0.0"