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" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.mohem_flutter_app"> package="com.mohem_flutter_app">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
@ -34,6 +35,17 @@
android:extractNativeLibs="true" android:extractNativeLibs="true"
android:networkSecurityConfig="@xml/network_security_config" android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"> 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 <activity
android:name=".MainActivity" android:name=".MainActivity"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" 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/models/mowadhafhi/get_transaction_attachment_model.dart';
import 'package:mohem_flutter_app/ui/screens/mowadhafhi/view_transaction_attachment.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:mohem_flutter_app/widgets/app_bar_widget.dart';
import 'package:open_file/open_file.dart';
import 'package:path_provider/path_provider.dart'; import 'package:path_provider/path_provider.dart';
class MowadhafhiRequestDetails extends StatefulWidget { class MowadhafhiRequestDetails extends StatefulWidget {
@ -245,9 +246,7 @@ class _RequestDetailsState extends State<MowadhafhiRequestDetails> {
try { try {
Utils.showLoading(context); Utils.showLoading(context);
getTransactionAttachmentModel = await MowadhafhiApiClient().getTransactionAttachments(attachmentID); getTransactionAttachmentModel = await MowadhafhiApiClient().getTransactionAttachments(attachmentID);
debugPrint(getTransactionAttachmentModel?.fileName);
Utils.hideLoading(context); Utils.hideLoading(context);
setState(() {});
handleTransactionAttachment(); handleTransactionAttachment();
} catch (ex) { } catch (ex) {
Utils.hideLoading(context); 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 { void handleTransactionAttachment() async {
String ext = ''; String ext = '';
String? rFile = getTransactionAttachmentModel!.base64String; String? rFile = getTransactionAttachmentModel!.base64String;
String? rFileExt = getTransactionAttachmentModel!.fileName; 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 { try {
Uint8List decodedBytes = base64Decode(rFile!.split("base64,").last); String path = await _createFileFromString(rFile!.split("base64,").last ?? "", ext ?? "");
Directory appDocumentsDirectory = await getApplicationDocumentsDirectory(); // 1 debugPrint(path);
imageFile = Io.File("${appDocumentsDirectory.path}/addImage$ext");
imageFile.writeAsBytesSync(decodedBytes); print(" file here: ${File(path).existsSync()}");
Navigator.push( await OpenFile.open(path);
context, } catch (ex) {
MaterialPageRoute( Utils.showToast("Cannot open file.");
builder: (BuildContext context) => ViewTransactionAttachment(
imageFile: imageFile,
),
),
);
} catch (e) {
logger.d(e);
}
} else {
Utils.showErrorDialog(context: context, onOkTapped: () {}, message: "Unable to view attachment");
} }
} }
} }

Loading…
Cancel
Save