♿ Share post as image on web
This commit is contained in:
@ -49,6 +49,7 @@ class _AttachmentListState extends State<AttachmentList> {
|
||||
bool _isLoading = true;
|
||||
bool _showMature = false;
|
||||
|
||||
// ignore: unused_field
|
||||
double _aspectRatio = 1;
|
||||
|
||||
List<Attachment?> _attachments = List.empty();
|
||||
|
@ -1,4 +1,3 @@
|
||||
import 'dart:io';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:file_saver/file_saver.dart';
|
||||
@ -7,9 +6,6 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_animate/flutter_animate.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:screenshot/screenshot.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:solian/exts.dart';
|
||||
@ -113,16 +109,17 @@ class _PostActionState extends State<PostAction> {
|
||||
maxHeight: double.infinity,
|
||||
),
|
||||
);
|
||||
final directory = await getApplicationDocumentsDirectory();
|
||||
final imageFile = await File(
|
||||
'${directory.path}/share_image_${DateFormat('yyyy-MM-dd-HH-mm-ss').format(DateTime.now())}.png',
|
||||
).create();
|
||||
await imageFile.writeAsBytes(image);
|
||||
|
||||
final filename = 'share_post#${widget.item.id}';
|
||||
|
||||
if (PlatformInfo.isAndroid || PlatformInfo.isIOS) {
|
||||
final box = context.findRenderObject() as RenderBox?;
|
||||
|
||||
final file = XFile(imageFile.path);
|
||||
final file = XFile.fromData(
|
||||
image,
|
||||
mimeType: 'image/png',
|
||||
name: filename,
|
||||
);
|
||||
await Share.shareXFiles(
|
||||
[file],
|
||||
subject: 'postShareSubject'.trParams({
|
||||
@ -132,15 +129,14 @@ class _PostActionState extends State<PostAction> {
|
||||
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
|
||||
);
|
||||
} else {
|
||||
await FileSaver.instance.saveAs(
|
||||
name: path.basename(imageFile.path),
|
||||
ext: path.extension(imageFile.path),
|
||||
final filepath = await FileSaver.instance.saveFile(
|
||||
name: filename,
|
||||
ext: 'png',
|
||||
mimeType: MimeType.png,
|
||||
file: imageFile,
|
||||
bytes: image,
|
||||
);
|
||||
context.showSnackbar('fileSavedAt'.trParams({'path': filepath}));
|
||||
}
|
||||
|
||||
await imageFile.delete();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -1,3 +1,4 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
||||
@ -73,50 +74,59 @@ class PostListEntryWidget extends StatelessWidget {
|
||||
required this.onUpdate,
|
||||
});
|
||||
|
||||
void _openActions(BuildContext context) {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
context: context,
|
||||
builder: (context) => PostAction(item: item),
|
||||
).then((value) {
|
||||
if (value is Future) {
|
||||
value.then((_) {
|
||||
onUpdate();
|
||||
});
|
||||
} else if (value != null) {
|
||||
onUpdate();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
child: PostItem(
|
||||
key: Key('p${item.id}'),
|
||||
item: item,
|
||||
isShowEmbed: isShowEmbed,
|
||||
isClickable: isNestedClickable,
|
||||
showFeaturedReply: showFeaturedReply,
|
||||
padding: padding,
|
||||
onComment: () {
|
||||
AppRouter.instance
|
||||
.pushNamed(
|
||||
'postEditor',
|
||||
extra: PostPublishArguments(reply: item),
|
||||
)
|
||||
.then((value) {
|
||||
if (value is Future) {
|
||||
value.then((_) {
|
||||
return TapRegion(
|
||||
child: GestureDetector(
|
||||
onLongPress: () => _openActions(context),
|
||||
child: PostItem(
|
||||
key: Key('p${item.id}'),
|
||||
item: item,
|
||||
isShowEmbed: isShowEmbed,
|
||||
isClickable: isNestedClickable,
|
||||
showFeaturedReply: showFeaturedReply,
|
||||
padding: padding,
|
||||
onComment: () {
|
||||
AppRouter.instance
|
||||
.pushNamed(
|
||||
'postEditor',
|
||||
extra: PostPublishArguments(reply: item),
|
||||
)
|
||||
.then((value) {
|
||||
if (value is Future) {
|
||||
value.then((_) {
|
||||
onUpdate();
|
||||
});
|
||||
} else if (value != null) {
|
||||
onUpdate();
|
||||
});
|
||||
} else if (value != null) {
|
||||
onUpdate();
|
||||
}
|
||||
});
|
||||
},
|
||||
).paddingSymmetric(vertical: 8),
|
||||
onLongPress: () {
|
||||
final AuthProvider auth = Get.find();
|
||||
if (auth.isAuthorized.isFalse) return;
|
||||
|
||||
showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
context: context,
|
||||
builder: (context) => PostAction(item: item),
|
||||
).then((value) {
|
||||
if (value is Future) {
|
||||
value.then((_) {
|
||||
onUpdate();
|
||||
}
|
||||
});
|
||||
} else if (value != null) {
|
||||
onUpdate();
|
||||
}
|
||||
});
|
||||
},
|
||||
).paddingSymmetric(vertical: 8),
|
||||
),
|
||||
onTapInside: (event) {
|
||||
if (event.buttons == kSecondaryMouseButton) {
|
||||
_openActions(context);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user