|
|
|
|
@ -1,3 +1,7 @@
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/classes/colors.dart';
|
|
|
|
|
@ -10,6 +14,8 @@ import 'package:mohem_flutter_app/provider/etqan_ovr_provider.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/classes/utils.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/widgets/app_bar_widget.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:open_filex/open_filex.dart';
|
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
|
|
|
|
|
|
class EtqanOvrRequestDetailed extends StatefulWidget {
|
|
|
|
|
const EtqanOvrRequestDetailed({Key? key}) : super(key: key);
|
|
|
|
|
@ -23,6 +29,24 @@ class _EtqanOvrRequestDetailedState extends State<EtqanOvrRequestDetailed> {
|
|
|
|
|
|
|
|
|
|
List<String> get hiddenFields => ['OVR Id', 'Is Anonymous'];
|
|
|
|
|
|
|
|
|
|
Future<void> _viewAttachment(BuildContext context, String base64Data) async {
|
|
|
|
|
try {
|
|
|
|
|
Uint8List bytes = base64.decode(base64Data);
|
|
|
|
|
String dir = (await getApplicationDocumentsDirectory()).path;
|
|
|
|
|
String ext = 'pdf';
|
|
|
|
|
if (base64Data.startsWith('/9j/')) {
|
|
|
|
|
ext = 'jpg';
|
|
|
|
|
} else if (base64Data.startsWith('iVBORw0KGgo')) {
|
|
|
|
|
ext = 'png';
|
|
|
|
|
}
|
|
|
|
|
File file = File("$dir/${DateTime.now().millisecondsSinceEpoch}.$ext");
|
|
|
|
|
await file.writeAsBytes(bytes);
|
|
|
|
|
OpenFilex.open(file.path);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
Utils.showToast("Cannot open attachment.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<EtqanGetIncidentRequestResponse> _getOrderedList(List<EtqanGetIncidentRequestResponse> list) {
|
|
|
|
|
List<EtqanGetIncidentRequestResponse> orderedList = [];
|
|
|
|
|
|
|
|
|
|
@ -48,7 +72,7 @@ class _EtqanOvrRequestDetailedState extends State<EtqanOvrRequestDetailed> {
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
var provider = context.read<EtqanOvrProviderModel>();
|
|
|
|
|
EtqanOvrProviderModel provider = context.read<EtqanOvrProviderModel>();
|
|
|
|
|
provider.fetchEtqanEmployeeIncidentRequests(context, provider.getTicketId);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
@ -57,7 +81,7 @@ class _EtqanOvrRequestDetailedState extends State<EtqanOvrRequestDetailed> {
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
appBar: AppBarWidget(context, title: LocaleKeys.etqanRequest.tr()),
|
|
|
|
|
appBar: AppBarWidget(context, title: LocaleKeys.incidentDetails.tr()),
|
|
|
|
|
body: Consumer<EtqanOvrProviderModel>(
|
|
|
|
|
builder: (BuildContext context, EtqanOvrProviderModel provider, Widget? child) {
|
|
|
|
|
if (provider.getEtqanEmployeeIncidnetRequest == null || provider.getEtqanEmployeeIncidnetRequest!.isEmpty) {
|
|
|
|
|
@ -74,7 +98,7 @@ class _EtqanOvrRequestDetailedState extends State<EtqanOvrRequestDetailed> {
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
borderRadius: BorderRadius.circular(15),
|
|
|
|
|
border: Border.all(color: const Color(0xffefefef), width: 1),
|
|
|
|
|
boxShadow: <BoxShadow>[BoxShadow(color: Colors.black.withOpacity(0.05), blurRadius: 10, offset: const Offset(0, 2))],
|
|
|
|
|
boxShadow: <BoxShadow>[BoxShadow(color: Colors.black.withValues(alpha: 0.05), blurRadius: 10, offset: const Offset(0, 2))],
|
|
|
|
|
),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
@ -83,6 +107,13 @@ class _EtqanOvrRequestDetailedState extends State<EtqanOvrRequestDetailed> {
|
|
|
|
|
int index = entry.key;
|
|
|
|
|
EtqanGetIncidentRequestResponse data = entry.value;
|
|
|
|
|
bool isLast = index == orderedList.length - 1;
|
|
|
|
|
bool isAttachment = data.key?.toLowerCase() == 'attachment';
|
|
|
|
|
|
|
|
|
|
String displayKey = context.locale.languageCode == "ar" ? (data.keyAr ?? data.key ?? "") : (data.key ?? "");
|
|
|
|
|
String displayValue = context.locale.languageCode == "ar" ? (data.valueAr ?? data.value ?? "") : (data.value ?? "");
|
|
|
|
|
|
|
|
|
|
bool hasSubValues = data.subValues != null && data.subValues!.isNotEmpty;
|
|
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Padding(
|
|
|
|
|
@ -90,9 +121,63 @@ class _EtqanOvrRequestDetailedState extends State<EtqanOvrRequestDetailed> {
|
|
|
|
|
child: Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Expanded(flex: 2, child: (data.key ?? "").toText12(isBold: true, color: MyColors.grey57Color)),
|
|
|
|
|
Expanded(flex: 2, child: displayKey.toText12(isBold: true, color: MyColors.grey57Color)),
|
|
|
|
|
8.width,
|
|
|
|
|
Expanded(flex: 3, child: (data.value ?? "-").toText14(color: MyColors.darkTextColor)),
|
|
|
|
|
Expanded(
|
|
|
|
|
flex: 3,
|
|
|
|
|
child:
|
|
|
|
|
isAttachment && hasSubValues
|
|
|
|
|
? Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children:
|
|
|
|
|
data.subValues!.asMap().entries.map((entry) {
|
|
|
|
|
int subIndex = entry.key;
|
|
|
|
|
String base64Data = entry.value;
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: EdgeInsets.only(bottom: subIndex < data.subValues!.length - 1 ? 8.0 : 0),
|
|
|
|
|
child: GestureDetector(
|
|
|
|
|
onTap: () => _viewAttachment(context, base64Data),
|
|
|
|
|
child: Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
mainAxisAlignment: context.locale.languageCode == "ar" ? MainAxisAlignment.end : MainAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
|
|
|
|
data.subValues!.length > 1 ? '${LocaleKeys.viewAttachment.tr()} ${subIndex + 1}' : LocaleKeys.viewAttachment.tr(),
|
|
|
|
|
// textAlign: context.locale.languageCode == "ar" ? TextAlign.start : TextAlign.start,
|
|
|
|
|
style: const TextStyle(
|
|
|
|
|
fontSize: 14,
|
|
|
|
|
color: MyColors.green9CColor,
|
|
|
|
|
decoration: TextDecoration.underline,
|
|
|
|
|
decorationColor: MyColors.green9CColor,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}).toList(),
|
|
|
|
|
)
|
|
|
|
|
: hasSubValues
|
|
|
|
|
? Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
if (displayValue.isNotEmpty) displayValue.toText14(color: MyColors.darkTextColor),
|
|
|
|
|
if (displayValue.isNotEmpty) 8.height,
|
|
|
|
|
...data.subValues!
|
|
|
|
|
.map(
|
|
|
|
|
(subValue) => Padding(
|
|
|
|
|
padding: const EdgeInsets.only(bottom: 4),
|
|
|
|
|
child: Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [const Text("• ", style: TextStyle(fontSize: 14)), Expanded(child: subValue.toText14(color: MyColors.darkTextColor))],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.toList(),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
: (displayValue.isNotEmpty ? displayValue : "-").toText14(color: MyColors.darkTextColor),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
@ -104,7 +189,7 @@ class _EtqanOvrRequestDetailedState extends State<EtqanOvrRequestDetailed> {
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
).paddingOnly(bottom: 20),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|