FIX Telegram Mime image share
This commit is contained in:
@@ -5,12 +5,17 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
import '../../app/icons/app_icons.dart';
|
||||
import '../../app/theme/app_colors.dart';
|
||||
import '../../core/widgets/arabic_text.dart';
|
||||
|
||||
const MethodChannel _androidShareChannel = MethodChannel(
|
||||
'com.jamshalat.app/share',
|
||||
);
|
||||
|
||||
String buildAyatShareText(Map<String, dynamic> ayat) {
|
||||
final arabic = (ayat['teksArab'] ?? '').toString().trim();
|
||||
final translation = (ayat['teksIndonesia'] ?? '').toString().trim();
|
||||
@@ -50,11 +55,7 @@ Future<void> showAyatShareSheet(
|
||||
try {
|
||||
final pngBytes = await _captureAyatShareCardPng(context, ayat);
|
||||
final file = await _writeAyatShareImage(pngBytes);
|
||||
await Share.shareXFiles(
|
||||
[XFile(file.path)],
|
||||
text: 'Ayat Hari Ini',
|
||||
subject: 'Ayat Hari Ini',
|
||||
);
|
||||
await _shareAyatImage(file);
|
||||
} catch (_) {
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context)
|
||||
@@ -224,12 +225,40 @@ Future<Uint8List> _captureAyatShareCardPng(
|
||||
}
|
||||
|
||||
Future<File> _writeAyatShareImage(Uint8List pngBytes) async {
|
||||
final directory = await Directory.systemTemp.createTemp('jamshalat_ayat_');
|
||||
final file = File('${directory.path}/ayat_hari_ini.png');
|
||||
final tempDirectory = await getTemporaryDirectory();
|
||||
final shareDirectory =
|
||||
Directory('${tempDirectory.path}/share_plus/jamshalat');
|
||||
if (!await shareDirectory.exists()) {
|
||||
await shareDirectory.create(recursive: true);
|
||||
}
|
||||
|
||||
final timestamp = DateTime.now().millisecondsSinceEpoch;
|
||||
final file = File('${shareDirectory.path}/ayat_hari_ini_$timestamp.png');
|
||||
await file.writeAsBytes(pngBytes, flush: true);
|
||||
return file;
|
||||
}
|
||||
|
||||
Future<void> _shareAyatImage(File file) async {
|
||||
if (Platform.isAndroid) {
|
||||
await _androidShareChannel.invokeMethod<void>('shareImage', {
|
||||
'path': file.path,
|
||||
'mimeType': 'image/png',
|
||||
'chooserTitle': 'Bagikan ayat',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await Share.shareXFiles(
|
||||
[
|
||||
XFile(
|
||||
file.path,
|
||||
mimeType: 'image/png',
|
||||
),
|
||||
],
|
||||
fileNameOverrides: const ['jamshalat_ayat_hari_ini.png'],
|
||||
);
|
||||
}
|
||||
|
||||
class _AyatShareCard extends StatelessWidget {
|
||||
const _AyatShareCard({
|
||||
required this.ayat,
|
||||
|
||||
Reference in New Issue
Block a user