Skip to content

Commit

Permalink
wip - ipad share bug
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyrat committed Aug 31, 2023
1 parent eee6073 commit 2282715
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions lib/widgets/binaries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,33 +216,42 @@ class BinaryCardWidget extends StatelessWidget {
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
TextButton.icon(
onPressed: () async {
WidgetsBinding.instance.addPostFrameCallback((_) async {
final attachmentSource = AttachmentSourceKdbx();
final bytes = await attachmentSource.readAttachmentBytes(attachment.value);
final mimeType = lookupMimeType(
attachment.key.key,
headerBytes: bytes.length > defaultMagicNumbersMaxLength
? Uint8List.sublistView(bytes, 0, defaultMagicNumbersMaxLength)
: null,
);
l.d('Sharing attachment with mimeType $mimeType');
Builder(
builder: (BuildContext context) {
return TextButton.icon(
onPressed: () async {
WidgetsBinding.instance.addPostFrameCallback((_) async {
final attachmentSource = AttachmentSourceKdbx();
final bytes = await attachmentSource.readAttachmentBytes(attachment.value);
final mimeType = lookupMimeType(
attachment.key.key,
headerBytes: bytes.length > defaultMagicNumbersMaxLength
? Uint8List.sublistView(bytes, 0, defaultMagicNumbersMaxLength)
: null,
);
l.d('Sharing attachment with mimeType $mimeType');

final tempDir = await getTemporaryDirectory();
final file = File('${tempDir.path}/${attachment.key.key}');
await file.create(recursive: true);
await file.writeAsBytes(bytes, flush: true);
try {
final xFile = XFile(file.path, mimeType: mimeType);
await Share.shareXFiles([xFile], subject: 'Kee Vault attachment');
} finally {
await file.delete();
}
});
final tempDir = await getTemporaryDirectory();
final file = File('${tempDir.path}/${attachment.key.key}');
await file.create(recursive: true);
await file.writeAsBytes(bytes, flush: true);
try {
final xFile = XFile(file.path, mimeType: mimeType);
final box = context.findRenderObject() as RenderBox?;
await Share.shareXFiles(
[xFile],
subject: 'Kee Vault attachment',
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
);
} finally {
await file.delete();
}
});
},
icon: Icon(Icons.share),
label: Text(str.share.toUpperCase()),
);
},
icon: Icon(Icons.share),
label: Text(str.share.toUpperCase()),
),
// TextButton.icon(
// onPressed: () async {
Expand Down

0 comments on commit 2282715

Please sign in to comment.