|
|
@ -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");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|