Updated Mowadhafi Attachment Handling

development_aamir
haroon amjad 10 months ago
parent fc3c1c057a
commit 0728cc3dd4

@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.mohem_flutter_app">
<uses-permission android:name="android.permission.INTERNET" />
@ -34,6 +35,17 @@
android:extractNativeLibs="true"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round">
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileProvider"
android:exported="false"
android:grantUriPermissions="true"
tools:replace="android:authorities">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/filepaths"
tools:replace="android:resource" />
</provider>
<activity
android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<root-path name="root" path="."/>
<external-path name="external_storage_directory" path="." />
</resources>

@ -17,6 +17,7 @@ import 'package:mohem_flutter_app/models/mowadhafhi/get_ticket_transactions.dart
import 'package:mohem_flutter_app/models/mowadhafhi/get_transaction_attachment_model.dart';
import 'package:mohem_flutter_app/ui/screens/mowadhafhi/view_transaction_attachment.dart';
import 'package:mohem_flutter_app/widgets/app_bar_widget.dart';
import 'package:open_file/open_file.dart';
import 'package:path_provider/path_provider.dart';
class MowadhafhiRequestDetails extends StatefulWidget {
@ -245,9 +246,7 @@ class _RequestDetailsState extends State<MowadhafhiRequestDetails> {
try {
Utils.showLoading(context);
getTransactionAttachmentModel = await MowadhafhiApiClient().getTransactionAttachments(attachmentID);
debugPrint(getTransactionAttachmentModel?.fileName);
Utils.hideLoading(context);
setState(() {});
handleTransactionAttachment();
} catch (ex) {
Utils.hideLoading(context);
@ -255,32 +254,29 @@ class _RequestDetailsState extends State<MowadhafhiRequestDetails> {
}
}
Future<String> _createFileFromString(String encodedStr, String ext) async {
Uint8List bytes = base64.decode(encodedStr);
String dir = (await getApplicationDocumentsDirectory()).path;
File file = File("$dir/" + DateTime.now().millisecondsSinceEpoch.toString() + "." + ext);
await file.writeAsBytes(bytes);
return file.path;
}
void handleTransactionAttachment() async {
String ext = '';
String? rFile = getTransactionAttachmentModel!.base64String;
String? rFileExt = getTransactionAttachmentModel!.fileName;
ext = "." + rFileExt!.split(".").last.toLowerCase();
ext = rFileExt!.split(".").last.toLowerCase();
if (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".gif" || ext == ".tiff") {
try {
Uint8List decodedBytes = base64Decode(rFile!.split("base64,").last);
Directory appDocumentsDirectory = await getApplicationDocumentsDirectory(); // 1
imageFile = Io.File("${appDocumentsDirectory.path}/addImage$ext");
imageFile.writeAsBytesSync(decodedBytes);
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) => ViewTransactionAttachment(
imageFile: imageFile,
),
),
);
} catch (e) {
logger.d(e);
}
} else {
Utils.showErrorDialog(context: context, onOkTapped: () {}, message: "Unable to view attachment");
try {
String path = await _createFileFromString(rFile!.split("base64,").last ?? "", ext ?? "");
debugPrint(path);
print(" file here: ${File(path).existsSync()}");
await OpenFile.open(path);
} catch (ex) {
Utils.showToast("Cannot open file.");
}
}
}

Loading…
Cancel
Save