|
|
|
|
@ -4,6 +4,7 @@ import 'dart:io';
|
|
|
|
|
import 'dart:math' as math;
|
|
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
|
|
|
|
import 'package:dotted_border/dotted_border.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter/rendering.dart';
|
|
|
|
|
@ -12,6 +13,7 @@ import 'package:http/http.dart' as http;
|
|
|
|
|
import 'package:just_audio/just_audio.dart';
|
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
import 'package:shared_storage/shared_storage.dart' as saf;
|
|
|
|
|
import 'package:tangheem/classes/colors.dart';
|
|
|
|
|
import 'package:tangheem/classes/consts.dart';
|
|
|
|
|
import 'package:tangheem/classes/utils.dart';
|
|
|
|
|
@ -185,7 +187,11 @@ class _AyaPlayerWidgetState extends State<AyaPlayerWidget> {
|
|
|
|
|
),
|
|
|
|
|
if (widget.voiceNoteList?.isNotEmpty ?? false)
|
|
|
|
|
commonIconButton("assets/icons/download_aya.svg", () async {
|
|
|
|
|
if (await _requestPermission()) {
|
|
|
|
|
if (Platform.isAndroid && (await DeviceInfoPlugin().androidInfo).version.sdkInt > 29) {
|
|
|
|
|
String filePath = widget.voiceNoteList[_player.currentIndex].exposeFilePath;
|
|
|
|
|
saveAudioToAboveAndroid32(filePath, "Tangheem-${widget.voiceNoteList[_player.currentIndex].userName ?? ""}-${widget.voiceNoteList[_player.currentIndex].fileName}",
|
|
|
|
|
widget.voiceNoteList[_player.currentIndex].fileType);
|
|
|
|
|
} else if (await _requestPermission()) {
|
|
|
|
|
saveToPhoneStorage(widget.voiceNoteList[_player.currentIndex].exposeFilePath, widget.voiceNoteList[_player.currentIndex].userName ?? "");
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast("يجب اعطاء الاذن لتنزيل الآية");
|
|
|
|
|
@ -393,4 +399,49 @@ class _AyaPlayerWidgetState extends State<AyaPlayerWidget> {
|
|
|
|
|
onResponse(false);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void saveAudioToAboveAndroid32(String pathUrl, String fileName, String fileType) async {
|
|
|
|
|
List<saf.UriPermission> _persistedPermissionUris = await saf.persistedUriPermissions();
|
|
|
|
|
if (_persistedPermissionUris.isNotEmpty) {
|
|
|
|
|
saf.UriPermission permissionUri = _persistedPermissionUris.first;
|
|
|
|
|
startFileDownloadAboveAndroid32(pathUrl, fileName, permissionUri.uri, fileType);
|
|
|
|
|
} else {
|
|
|
|
|
Uri selectedDocumentUris = await saf.openDocumentTree();
|
|
|
|
|
if (selectedDocumentUris == null) return;
|
|
|
|
|
saveAudioToAboveAndroid32(pathUrl, fileName, fileType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void startFileDownloadAboveAndroid32(String url, String fileName, Uri persistentUri, String fileType) async {
|
|
|
|
|
try {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
//String path = await Utils.getStoragePath(fileName);
|
|
|
|
|
Utils.downloadFileAboveAndroid32(ApiConsts.baseUrl + url, "path", onResponse: (bytes) async {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (bytes.isNotEmpty) {
|
|
|
|
|
final documentFile = await persistentUri.toDocumentFile();
|
|
|
|
|
final child = await documentFile?.child(fileName);
|
|
|
|
|
if (child == null) {
|
|
|
|
|
documentFile?.createFileAsBytes(
|
|
|
|
|
mimeType: fileType,
|
|
|
|
|
bytes: bytes,
|
|
|
|
|
displayName: fileName,
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
documentFile?.writeToFileAsBytes(
|
|
|
|
|
bytes: bytes,
|
|
|
|
|
mode: FileMode.write,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils.showToast("تم حفظ الملف بنجاح");
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast("فشل حفظ الملف ، حاول مرة أخرى");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
print(ex);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|