|
|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_svg/svg.dart';
|
|
|
|
|
import 'package:just_audio/just_audio.dart';
|
|
|
|
|
@ -7,9 +8,11 @@ import 'package:path_provider/path_provider.dart';
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
import 'package:record_mp3/record_mp3.dart';
|
|
|
|
|
import 'package:tangheem/classes/colors.dart';
|
|
|
|
|
import 'package:tangheem/classes/consts.dart';
|
|
|
|
|
import 'package:tangheem/classes/utils.dart';
|
|
|
|
|
import 'package:tangheem/extensions/string_extensions.dart';
|
|
|
|
|
import 'package:tangheem/extensions/widget_extensions.dart';
|
|
|
|
|
import 'package:shared_storage/shared_storage.dart' as saf;
|
|
|
|
|
|
|
|
|
|
class AyaRecordWidget extends StatefulWidget {
|
|
|
|
|
AyaRecordWidget({Key key}) : super(key: key);
|
|
|
|
|
@ -219,7 +222,13 @@ class _AyaRecordWidgetState extends State<AyaRecordWidget> {
|
|
|
|
|
InkWell(
|
|
|
|
|
borderRadius: BorderRadius.circular(20),
|
|
|
|
|
onTap: () async {
|
|
|
|
|
if (await _requestStoragePermission()) {
|
|
|
|
|
if (Platform.isAndroid && (await DeviceInfoPlugin().androidInfo).version.sdkInt > 29) {
|
|
|
|
|
if (recordFilePath != null && File(recordFilePath).existsSync()) {
|
|
|
|
|
saveAudioToAboveAndroid32(recordFilePath, "Tangheem${DateTime.now().millisecondsSinceEpoch}.mp3", "audio/mpeg");
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast("يجب عليك تسجيل صوتك أولا");
|
|
|
|
|
}
|
|
|
|
|
} else if (await _requestStoragePermission()) {
|
|
|
|
|
if (recordFilePath != null && File(recordFilePath).existsSync()) {
|
|
|
|
|
saveToPhoneStorage(recordFilePath);
|
|
|
|
|
} else {
|
|
|
|
|
@ -231,7 +240,7 @@ class _AyaRecordWidgetState extends State<AyaRecordWidget> {
|
|
|
|
|
},
|
|
|
|
|
child: Container(
|
|
|
|
|
height: 31,
|
|
|
|
|
width: 135,
|
|
|
|
|
width: 135,
|
|
|
|
|
padding: EdgeInsets.only(left: 12, right: 12),
|
|
|
|
|
alignment: Alignment.center,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
@ -321,4 +330,41 @@ class _AyaRecordWidgetState extends State<AyaRecordWidget> {
|
|
|
|
|
await file.copy(storagePath);
|
|
|
|
|
Utils.showToast("تم التنزيل");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void saveAudioToAboveAndroid32(String pathUrl, String fileName, String fileType) async {
|
|
|
|
|
List<saf.UriPermission> _persistedPermissionUris = await saf.persistedUriPermissions();
|
|
|
|
|
if (_persistedPermissionUris.isNotEmpty) {
|
|
|
|
|
saf.UriPermission permissionUri = _persistedPermissionUris.first;
|
|
|
|
|
startFileAboveAndroid32(pathUrl, fileName, permissionUri.uri, fileType);
|
|
|
|
|
} else {
|
|
|
|
|
Uri selectedDocumentUris = await saf.openDocumentTree();
|
|
|
|
|
if (selectedDocumentUris == null) return;
|
|
|
|
|
saveAudioToAboveAndroid32(pathUrl, fileName, fileType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void startFileAboveAndroid32(String filePath, String fileName, Uri persistentUri, String fileType) async {
|
|
|
|
|
try {
|
|
|
|
|
File file = File(filePath);
|
|
|
|
|
final documentFile = await persistentUri.toDocumentFile();
|
|
|
|
|
final child = await documentFile?.child(fileName);
|
|
|
|
|
if (child == null) {
|
|
|
|
|
documentFile?.createFileAsBytes(
|
|
|
|
|
mimeType: fileType,
|
|
|
|
|
bytes: file.readAsBytesSync(),
|
|
|
|
|
displayName: fileName,
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
documentFile?.writeToFileAsBytes(
|
|
|
|
|
bytes: file.readAsBytesSync(),
|
|
|
|
|
mode: FileMode.write,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Utils.showToast("تم حفظ الملف بنجاح");
|
|
|
|
|
} catch (ex) {
|
|
|
|
|
print(ex);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|