Это происходит только для Android в Productions.
Код: Выделить всё
Future shareImage(QR qr) async {
final File? image = await getImage(qr);
if (image == null) return;
final Uint8List bytes = await image.readAsBytes();
final String safeFileName =
'${qr.qrCode.replaceAll(RegExp(r'[^\w\-]+'), '_')}.png';
try {
final xFile = XFile.fromData(
bytes,
name: safeFileName,
mimeType: 'image/png',
);
await SharePlus.instance.share(ShareParams(
files: [xFile],
title: 'QR',
text: _getQRText(qr),
));
} catch (e) {
NotificationHelper.error('Share Failed', 'Could not share QR: $e');
}
}
androidmanifest.xml[/b]
Код: Выделить всё
< /code>
У меня также есть следующее в манифестном файле. < /p>
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
< /code>
У меня есть аналогичная функция, в которой XML -файл возвращается из API и должен быть обмен. У этого есть такая же проблема. < /P>
void downloadAndSaveFile(
BuildContext context, dynamic response, String? filename) async {
final File? file = await _generateTempFile(filename!, response);
if (file != null) {
_shareFile(file, filename);
} else {
NotificationHelper.error('Download Failed', 'Could not save the file.');
}
}
Future _generateTempFile(String filename, List bytes) async {
try {
if (bytes.isEmpty) {
NotificationHelper.error(
'File Error', 'Response is empty – cannot create file.');
return null;
}
final tempDir = await getTemporaryDirectory();
final file = File('${tempDir.path}/$filename');
await file.writeAsBytes(bytes, flush: true);
return file;
} catch (e) {
NotificationHelper.error('File Error', 'Unable to create temp file: $e');
return null;
}
}
Future _shareFile(File file, String? filename) async {
if (filename == null) return;
try {
final Uint8List bytes = await file.readAsBytes();
final xFile = XFile.fromData(
bytes,
name: filename,
mimeType: 'application/octet-stream',
);
await SharePlus.instance.share(
ShareParams(
files: [xFile],
fileNameOverrides: [filename],
title: filename,
text: filename,
),
);
} catch (e) {
NotificationHelper.error('Share Failed', 'Could not share file: $e');
}
}
Любая справка.>
Подробнее здесь: https://stackoverflow.com/questions/796 ... us-package