diff --git a/lib/extensions/string_extensions.dart b/lib/extensions/string_extensions.dart new file mode 100644 index 00000000..48d6e8b1 --- /dev/null +++ b/lib/extensions/string_extensions.dart @@ -0,0 +1,8 @@ +import 'package:intl/intl.dart'; + +extension StringExtensions on String { + String get toServiceRequestCardFormat { + DateTime dateTime = DateTime.tryParse(this); + return "${DateFormat('dd MMM, yyyy').format(dateTime)}\n${DateFormat('hh:mm a').format(dateTime)}"; + } +} diff --git a/lib/extensions/text_extensions.dart b/lib/extensions/text_extensions.dart index f9424b81..b6767296 100644 --- a/lib/extensions/text_extensions.dart +++ b/lib/extensions/text_extensions.dart @@ -81,7 +81,7 @@ abstract class AppTextStyles { static final TextStyle heading5 = TextStyle( fontSize: 19.toScreenWidth, fontWeight: FontWeight.w500, - height: 1.47, + //height: 1.47, fontStyle: FontStyle.normal, decoration: TextDecoration.none, ); @@ -146,6 +146,7 @@ extension FilesExtension on String { BoxFit fit = BoxFit.contain, }) => SvgPicture.asset("assets/images/$this.svg", width: width?.toScreenWidth, height: height?.toScreenHeight, color: color, fit: fit); + Image toPngAsset({ int width, int height, diff --git a/lib/models/service_request/service_request.dart b/lib/models/service_request/service_request.dart index 836112c3..5769d0c1 100644 --- a/lib/models/service_request/service_request.dart +++ b/lib/models/service_request/service_request.dart @@ -90,6 +90,8 @@ class ServiceRequest { List list = parsedJson["attachmentsCallRequest"]; images = list.map((e) => URLs.getFileUrl(e["name"])).toList(); } + // print(parsedJson["requestedDate"]??""); + return ServiceRequest( id: parsedJson["id"].toString(), requestCode: parsedJson["callNo"].toString(), @@ -101,7 +103,7 @@ class ServiceRequest { deviceEnName: parsedJson["asset"]["modelDefinition"]["assetName"] ?? "", devicePhotos: images, deviceSerialNumber: parsedJson["asset"]["assetSerialNo"], - date: DateTime.tryParse(parsedJson["requestedDate"] ?? "").toString().split(" ").first, + date: DateTime.tryParse(parsedJson["requestedDate"] ?? "").toString(), // todo. add requeste time param for time callComments: parsedJson["callComments"], comments: parsedJson["comments"], diff --git a/lib/views/app_style/colors.dart b/lib/views/app_style/colors.dart index fb1aa4b2..92483a42 100644 --- a/lib/views/app_style/colors.dart +++ b/lib/views/app_style/colors.dart @@ -20,8 +20,58 @@ class AColors { static Color inputFieldBackgroundColor = Color(0xfff5f5f5); static Color greyEF = Color(0xffEFEFEF); + static Color statusYellow = const Color(0xFF886300); + static Color statusYellowLight = const Color(0xFFFFEDBC); + static Color statusGreen = const Color(0xFF62BE96); + static Color statusGreenLight = const Color(0xFF62BE96); + static Color statusRed = const Color(0xFF8C0409); + static Color statusRedLight = const Color(0xFFFFDBDC); + static Color statusBlue = const Color(0xFF4A8DB7); + static Color statusBlueLight = const Color(0xFFA2E2F8); + static Color statusDefault = const Color(0xFF3B3D4A); + + // Color getRequestStatusColor(String status) { + // switch (status) { + // case "in progress": + // return AColors.statusYellowLight; + // case "completed": + // return AColors.statusGreenLight; + // case "high priority": + // return AColors.statusRedLight; + // case "low priority": + // return AColors.statusGreenLight; + // case "open": + // return AColors.statusBlueLight; + // default: + // return AColors.statusDefault; + // } + // } + static Color getRequestStatusColor(int id) { switch (id) { + case 1: + return AColors.statusBlue; + case 2: + return AColors.statusYellowLight; + case 4: + return AColors.statusRedLight; + case 6: + return AColors.statusGreenLight; + case 5: + return AColors.orange; + case 8: + return AColors.statusGreenLight; + case 9: + return AColors.orange; + default: + return AColors.statusDefault; + } + } + + static Color getRequestStatusTextColor(int id) { + switch (id) { + case 2: + return AColors.statusYellow; case 4: return AColors.deepRed; case 6: @@ -33,7 +83,7 @@ class AColors { case 9: return AColors.orange; default: - return AColors.grey; + return AColors.white; } } @@ -44,7 +94,28 @@ class AColors { case 1: return AColors.green; default: - return AColors.grey; + return AColors.statusDefault; + } + } + + static Color getPriorityStatusTextColor(int id) { + switch (id) { + case 81: + return AColors.white; + case 82: + return AColors.statusRed; + default: + return AColors.statusDefault; + } + } + static Color getPriorityStatusColor(int id) { + switch (id) { + case 81: + return AColors.statusGreenLight; + case 82: + return AColors.statusRedLight; + default: + return AColors.statusDefault; } } } diff --git a/lib/views/pages/sub_workorder/workorder_item.dart b/lib/views/pages/sub_workorder/workorder_item.dart index 574fa0fe..8c2915f2 100644 --- a/lib/views/pages/sub_workorder/workorder_item.dart +++ b/lib/views/pages/sub_workorder/workorder_item.dart @@ -139,7 +139,7 @@ class WorkOrderItem extends StatelessWidget { ), ), ), - if (item.callRequest.status?.id != null) StatusLabel(label: item.callRequest.status.name, color: AColors.getGasStatusColor(item.callRequest.status.id)), + if (item.callRequest.status?.id != null) StatusLabel(label: item.callRequest.status.name, backgroundColor: AColors.getGasStatusColor(item.callRequest.status.id)), ], ), ], diff --git a/lib/views/pages/user/gas_refill/gas_refill_details.dart b/lib/views/pages/user/gas_refill/gas_refill_details.dart index 39422b24..060ec9ed 100644 --- a/lib/views/pages/user/gas_refill/gas_refill_details.dart +++ b/lib/views/pages/user/gas_refill/gas_refill_details.dart @@ -215,7 +215,7 @@ class _GasRefillDetailsState extends State { textScaleFactor: AppStyle.getScaleFactor(context), ), ), - if (_model.status?.id != null) StatusLabel(label: _model.status.name, color: AColors.getGasStatusColor(_model.status.id)), + if (_model.status?.id != null) StatusLabel(label: _model.status.name, backgroundColor: AColors.getGasStatusColor(_model.status.id)), ], ), const SizedBox( diff --git a/lib/views/pages/user/requests/request_details.dart b/lib/views/pages/user/requests/request_details.dart index 35b78099..457c9d9c 100644 --- a/lib/views/pages/user/requests/request_details.dart +++ b/lib/views/pages/user/requests/request_details.dart @@ -5,11 +5,17 @@ import 'package:test_sa/controllers/localization/localization.dart'; import 'package:test_sa/controllers/providers/api/service_requests_provider.dart'; import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; +import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/extensions/int_extensions.dart'; +import 'package:test_sa/extensions/string_extensions.dart'; +import 'package:test_sa/extensions/text_extensions.dart'; import 'package:test_sa/extensions/widget_extensions.dart'; +import 'package:test_sa/models/enums/translation_keys.dart'; import 'package:test_sa/models/enums/user_types.dart'; import 'package:test_sa/models/service_request/service_request.dart'; import 'package:test_sa/models/subtitle.dart'; +import 'package:test_sa/new_views/common_widgets/app_filled_button.dart'; +import 'package:test_sa/new_views/common_widgets/default_app_bar.dart'; import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/pages/user/requests/create_request.dart'; @@ -44,9 +50,113 @@ class RequestDetailsPage extends StatelessWidget { ServiceRequestsProvider _serviceRequestsProvider = Provider.of(context); _serviceRequestsProvider.getServiceRequestObjectById(requestId: serviceRequest.id); + Widget informationCard() { + return Container( + decoration: ShapeDecoration( + color: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(20), + ), + shadows: const [BoxShadow(color: Color(0x07000000), blurRadius: 14, offset: Offset(0, 0), spreadRadius: 0)], + ), + child: Column( + children: [ + Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + StatusLabel( + label: serviceRequest.priority.name, + id: serviceRequest.priority.id, + textColor: AColors.getPriorityStatusTextColor(serviceRequest.priority.id), + backgroundColor: AColors.getPriorityStatusColor(serviceRequest.priority.id)), + 8.width, + StatusLabel( + label: serviceRequest.statusLabel, + textColor: AColors.getRequestStatusTextColor(serviceRequest.statusValue), + backgroundColor: AColors.getRequestStatusColor(serviceRequest.statusValue)), + 1.width.expanded, + Text(serviceRequest.date.toServiceRequestCardFormat, textAlign: TextAlign.end, style: AppTextStyles.tinyFont.copyWith(color: const Color(0xFF3B3D4A))), + ], + ), + 8.height, + Text(serviceRequest.deviceEnName, style: AppTextStyles.heading5.copyWith(color: const Color(0xFF3B3D4A))), + Text( + '${_subtitle.assetNumber}: ${serviceRequest.device.number}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + Text( + 'Request Type: ${serviceRequest.type.name}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + Text( + 'Request No: ${serviceRequest.requestCode}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + 8.height, + const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1), + 8.height, + Text( + 'Manufacture: ${serviceRequest.device.modelDefinition.manufacturerName}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + Text( + 'Model: ${serviceRequest.device.modelDefinition.modelName}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + 8.height, + const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1), + 8.height, + if ((serviceRequest.callComments ?? "").isNotEmpty) ...[ + Text( + serviceRequest.callComments, + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + 8.height, + const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1), + ], + if (serviceRequest.devicePhotos.isNotEmpty) ...[ + FilesList(images: serviceRequest.devicePhotos), + const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1), + ], + if (serviceRequest.audio?.isNotEmpty == true) ...[ + 16.height, + ASoundPlayer( + audio: serviceRequest.audio, + ), + 16.height, + const Divider(color: Color(0xFFEAF1F4), height: 1, thickness: 1), + ], + Row( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + 'View Comments', + style: AppTextStyles.bodyText.copyWith(color: const Color(0xFF4A8DB7)), + ), + 4.width, + const Icon( + Icons.arrow_forward, + color: Color(0xFF4A8DB7), + size: 14, + ) + ], + ), + ], + ).paddingAll(16), + ], + ), + ); + } + return DefaultTabController( length: 2, child: Scaffold( + appBar: const DefaultAppBar(title: TranslationKeys.serviceRequest), + backgroundColor: const Color(0xfff8f9fb), body: SafeArea( child: FutureBuilder( future: _serviceRequestsProvider.getServiceRequestObjectById(requestId: serviceRequest.id), @@ -150,45 +260,6 @@ class RequestDetailsPage extends StatelessWidget { images: serviceRequest.devicePhotos, ), ).paddingOnly(top: 4, bottom: 4), - - // Column( - // children: [ - // SizedBox( - // height: 8, - // ), - // MaterialButton( - // padding: EdgeInsets.zero, - // onPressed: () { - // Navigator.of(context).push(MaterialPageRoute( - // builder: (_) => Scaffold( - // body: InteractiveViewer( - // child: Center( - // child: ImageLoader( - // url: serviceRequest.devicePhotos.first, - // boxFit: BoxFit.contain, - // ), - // ), - // ), - // ))); - // }, - // child: SizedBox( - // height: 140 * AppStyle.getScaleFactor(context), - // width: MediaQuery.of(context).size.width, - // child: ImageLoader( - // url: serviceRequest.devicePhotos.first, - // boxFit: BoxFit.cover, - // ), - // ), - // ), - // SizedBox(height: 8), - // SizedBox( - // height: 60 * AppStyle.getScaleFactor(context), - // child: FilesList( - // images: serviceRequest.devicePhotos, - // ), - // ), - // ], - // ), TabBar(labelColor: AColors.primaryColor, tabs: [ Tab( text: _subtitle.general, @@ -203,121 +274,127 @@ class RequestDetailsPage extends StatelessWidget { Expanded( child: TabBarView( children: [ - ListView( - padding: EdgeInsets.symmetric(horizontal: 16), + Column( children: [ - RequestInfoRow( - title: _subtitle.callId, - info: serviceRequest.requestCode, - ), - RequestInfoRow( - title: "Asset Number", - info: serviceRequest.deviceNumber, - ), - RequestInfoRow( - title: _subtitle.assetName, - info: serviceRequest.deviceEnName, - ), - RequestInfoRow( - title: _subtitle.deviceModel, - info: serviceRequest.deviceModel, - ), - RequestInfoRow( - title: _subtitle.engineerName, - info: serviceRequest.engineerName, - ), - RequestInfoRow( - title: _subtitle.engineerPhone, - info: serviceRequest.engineerMobile, - ), - RequestInfoRow( - title: _subtitle.date, - info: serviceRequest.date, - ), - serviceRequest.nextVisitDate == null - ? SizedBox.shrink() - : RequestInfoRow( - title: _subtitle.nextVisitDate, - info: DateFormat('EE dd/MM/yyyy').format(serviceRequest.nextVisitDate), - ), - Row( + ListView( + padding: const EdgeInsets.all(16), children: [ - Expanded( - child: Text( - "${_subtitle.status} : ", - style: Theme.of(context).textTheme.subtitle1, - textScaleFactor: AppStyle.getScaleFactor(context), - ), + informationCard(), + RequestInfoRow( + title: _subtitle.callId, + info: serviceRequest.requestCode, + ), + RequestInfoRow( + title: "Asset Number", + info: serviceRequest.deviceNumber, + ), + RequestInfoRow( + title: _subtitle.assetName, + info: serviceRequest.deviceEnName, + ), + RequestInfoRow( + title: _subtitle.deviceModel, + info: serviceRequest.deviceModel, + ), + RequestInfoRow( + title: _subtitle.engineerName, + info: serviceRequest.engineerName, + ), + RequestInfoRow( + title: _subtitle.engineerPhone, + info: serviceRequest.engineerMobile, + ), + RequestInfoRow( + title: _subtitle.date, + info: serviceRequest.date, ), - StatusLabel(label: serviceRequest.statusLabel, color: AColors.getRequestStatusColor(serviceRequest.statusValue)), + serviceRequest.nextVisitDate == null + ? SizedBox.shrink() + : RequestInfoRow( + title: _subtitle.nextVisitDate, + info: DateFormat('EE dd/MM/yyyy').format(serviceRequest.nextVisitDate), + ), + Row( + children: [ + Expanded( + child: Text( + "${_subtitle.status} : ", + style: Theme.of(context).textTheme.subtitle1, + textScaleFactor: AppStyle.getScaleFactor(context), + ), + ), + StatusLabel(label: serviceRequest.statusLabel, backgroundColor: AColors.getRequestStatusColor(serviceRequest.statusValue)), + ], + ), + Divider( + color: Theme.of(context).primaryColor, + ), + RequestInfoRow( + title: _subtitle.hospital, + info: serviceRequest.hospitalName, + ), + RequestInfoRow( + title: _subtitle.unite, + info: serviceRequest.departmentName, + ), + // RequestInfoRow( + // title: _subtitle.deviceArName, + // content: serviceRequest.deviceArName, + // ), + // RequestInfoRow( + // title: _subtitle.deviceName, + // content: serviceRequest.deviceEnName, + // ), + RequestInfoRow( + title: _subtitle.maintenanceIssue, + content: serviceRequest.callComments, + ), + if (serviceRequest.audio?.isNotEmpty == true) + ASoundPlayer( + audio: serviceRequest.audio, + ), + // + // Center( + // child: Padding( + // padding: EdgeInsets.all(32), + // child: AButton( + // text: _subtitle.duplicateRequest, + // onPressed: () async { + // bool result = await showDialog( + // context: context, + // builder: (_) => AAlertDialog( + // title: _subtitle.duplicateAlert, + // content: _subtitle.duplicateAlertMessage, + // ) + // ); + // if(result == true){ + // showDialog( + // context: context, + // builder: (context){ + // return Center(child: CircularProgressIndicator()); + // } + // ); + // int status = await _serviceRequestsProvider.createDuplicatedReport( + // host: _settingProvider.host, + // user: _userProvider.user, + // request: serviceRequest + // ); + // Navigator.of(context).pop(); + // ScaffoldMessenger.of(context).showSnackBar( + // SnackBar( + // content: Text( + // HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle) + // ) + // ) + // ); + // } + // }, + // ), + // ), + // ) ], - ), - Divider( - color: Theme.of(context).primaryColor, - ), - RequestInfoRow( - title: _subtitle.hospital, - info: serviceRequest.hospitalName, - ), - RequestInfoRow( - title: _subtitle.unite, - info: serviceRequest.departmentName, - ), - // RequestInfoRow( - // title: _subtitle.deviceArName, - // content: serviceRequest.deviceArName, - // ), - // RequestInfoRow( - // title: _subtitle.deviceName, - // content: serviceRequest.deviceEnName, - // ), - RequestInfoRow( - title: _subtitle.maintenanceIssue, - content: serviceRequest.callComments, - ), - if (serviceRequest.audio?.isNotEmpty == true) - ASoundPlayer( - audio: serviceRequest.audio, - ), - // - // Center( - // child: Padding( - // padding: EdgeInsets.all(32), - // child: AButton( - // text: _subtitle.duplicateRequest, - // onPressed: () async { - // bool result = await showDialog( - // context: context, - // builder: (_) => AAlertDialog( - // title: _subtitle.duplicateAlert, - // content: _subtitle.duplicateAlertMessage, - // ) - // ); - // if(result == true){ - // showDialog( - // context: context, - // builder: (context){ - // return Center(child: CircularProgressIndicator()); - // } - // ); - // int status = await _serviceRequestsProvider.createDuplicatedReport( - // host: _settingProvider.host, - // user: _userProvider.user, - // request: serviceRequest - // ); - // Navigator.of(context).pop(); - // ScaffoldMessenger.of(context).showSnackBar( - // SnackBar( - // content: Text( - // HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle) - // ) - // ) - // ); - // } - // }, - // ), - // ), - // ) + ).expanded, + AppFilledButton(label: TranslationKeys.login, maxWidth: true, onPressed: () {}).paddingOnly(left: 16, right: 16, bottom: 24), ], ), // workOrders.isEmpty ? diff --git a/lib/views/widgets/device_trancfer/device_transfer_info_section.dart b/lib/views/widgets/device_trancfer/device_transfer_info_section.dart index 29f519f3..a57d0ee6 100644 --- a/lib/views/widgets/device_trancfer/device_transfer_info_section.dart +++ b/lib/views/widgets/device_trancfer/device_transfer_info_section.dart @@ -66,7 +66,7 @@ class DeviceTransferInfoSection extends StatelessWidget { ), RequestInfoRow( title: subtitle.status, - infoWidget: StatusLabel(label: info.status?.name, color: AColors.getGasStatusColor(info.status?.id)), + infoWidget: StatusLabel(label: info.status?.name, backgroundColor: AColors.getGasStatusColor(info.status?.id)), ), ], ); diff --git a/lib/views/widgets/device_trancfer/device_transfer_item.dart b/lib/views/widgets/device_trancfer/device_transfer_item.dart index b2a923b7..8061f679 100644 --- a/lib/views/widgets/device_trancfer/device_transfer_item.dart +++ b/lib/views/widgets/device_trancfer/device_transfer_item.dart @@ -78,7 +78,7 @@ class DeviceTransferItem extends StatelessWidget { ), ), StatusLabel( - color: AColors.getRequestStatusColor(item.sender.status?.id), + backgroundColor: AColors.getRequestStatusColor(item.sender.status?.id), label: item.sender.status?.name, ) ], @@ -117,7 +117,7 @@ class DeviceTransferItem extends StatelessWidget { ), ), StatusLabel( - color: AColors.getRequestStatusColor(item.receiver.status?.id), + backgroundColor: AColors.getRequestStatusColor(item.receiver.status?.id), label: item.receiver.status?.name, ) ], diff --git a/lib/views/widgets/gas_refill/gas_refill_item.dart b/lib/views/widgets/gas_refill/gas_refill_item.dart index 17b2f38a..7622ab35 100644 --- a/lib/views/widgets/gas_refill/gas_refill_item.dart +++ b/lib/views/widgets/gas_refill/gas_refill_item.dart @@ -71,7 +71,7 @@ class GasRefillItem extends StatelessWidget { Expanded( child: Text(subtitle.status, style: Theme.of(context).textTheme.titleSmall.copyWith(color: onItemColor)), ), - if (item.status?.id != null) StatusLabel(label: item.status.name, color: AColors.getGasStatusColor(item.status.id)), + if (item.status?.id != null) StatusLabel(label: item.status.name, backgroundColor: AColors.getGasStatusColor(item.status.id)), ], ), if (item?.expectedDate != null) Divider(color: onItemColor), diff --git a/lib/views/widgets/images/files_list.dart b/lib/views/widgets/images/files_list.dart index d7f21dff..2280b272 100644 --- a/lib/views/widgets/images/files_list.dart +++ b/lib/views/widgets/images/files_list.dart @@ -21,6 +21,72 @@ class FilesList extends StatelessWidget { @override Widget build(BuildContext context) { + return GridView.builder( + padding: const EdgeInsets.only(top: 16, bottom: 16), + physics: const NeverScrollableScrollPhysics(), + shrinkWrap: true, + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 6, mainAxisSpacing: 8, crossAxisSpacing: 8), + itemCount: images?.length ?? 0, + itemBuilder: (context, itemIndex) { + if (images[itemIndex] == null || !images[itemIndex].contains(".")) { + return Text("Bad\nFile"); + } + var isImage = images[itemIndex].split(".").last.toLowerCase() == "png" || images[itemIndex].split(".").last.toLowerCase() == "jpg" || images[itemIndex].split(".").last.toLowerCase() == "jpeg"; + var isPdf = images[itemIndex].split(".").last.toLowerCase() == "pdf"; + var isExcel = images[itemIndex].split(".").last.toLowerCase() == "xlsx"; + + return Container( + decoration: ShapeDecoration( + color: Colors.white, + shape: RoundedRectangleBorder( + side: const BorderSide(width: 1, color: Color(0xFFEAF1F4)), + borderRadius: BorderRadius.circular(8), + ), + ), + child: ClipRRect( + borderRadius: BorderRadius.circular(8), + child: (isImage + ? (_isLocalUrl(images[itemIndex]) + ? Image.file(File(images[itemIndex])) + : ImageLoader( + url: images[itemIndex], + boxFit: BoxFit.cover, + height: 48, + width: 48, + )) + : Image.asset("assets/images/${isPdf ? "pdf" : isExcel ? "excel" : "doc"}.png")), + ), + ).onPress(() async { + if (isImage) { + Navigator.of(context).push( + MaterialPageRoute( + builder: (_) => Scaffold( + body: SafeArea( + child: Stack( + children: [ + InteractiveViewer(child: Image(image: (_isLocalUrl(images[itemIndex]) ? FileImage(File(images[itemIndex])) : NetworkImage(images[itemIndex])))).center, + const ABackButton(), + ], + ), + ), + ), + ), + ); + } else if (_isLocalUrl(images[itemIndex])) { + OpenFile.open(images[itemIndex]); + } else { + try { + if (!await launchUrl(Uri.parse(images[itemIndex]), mode: LaunchMode.externalApplication)) { + Fluttertoast.showToast(msg: "UnExpected Error with file."); + throw Exception('Could not launch '); + } + } catch (ex) { + Fluttertoast.showToast(msg: "No Viewer found."); + } + } + }); + }, + ); return ListView.separated( padding: padding ?? EdgeInsets.symmetric(horizontal: 32 * AppStyle.getScaleFactor(context)), diff --git a/lib/views/widgets/loaders/image_loader.dart b/lib/views/widgets/loaders/image_loader.dart index 7093d0a3..582dd94a 100644 --- a/lib/views/widgets/loaders/image_loader.dart +++ b/lib/views/widgets/loaders/image_loader.dart @@ -6,7 +6,9 @@ class ImageLoader extends StatelessWidget { final BoxFit boxFit; final Color color; final Alignment alignment; - const ImageLoader({Key key, @required this.url, this.boxFit, this.color, this.alignment}) : super(key: key); + final double width; + final double height; + const ImageLoader({Key key, @required this.url, this.boxFit, this.color, this.alignment, this.width, this.height}) : super(key: key); @override Widget build(BuildContext context) { @@ -14,6 +16,8 @@ class ImageLoader extends StatelessWidget { imageUrl: url ?? "", fit: boxFit ?? BoxFit.cover, alignment: Alignment.center, + width: width, + height: height, placeholder: (context, url) => const Center(child: CircularProgressIndicator()), errorWidget: (context, url, error) => const Icon(Icons.broken_image_rounded), ); diff --git a/lib/views/widgets/requests/request_status.dart b/lib/views/widgets/requests/request_status.dart index 7f606a44..26fa2352 100644 --- a/lib/views/widgets/requests/request_status.dart +++ b/lib/views/widgets/requests/request_status.dart @@ -1,24 +1,105 @@ import 'package:flutter/material.dart'; +import 'package:test_sa/extensions/text_extensions.dart'; import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/app_style/sizing.dart'; class StatusLabel extends StatelessWidget { - final String label; - final Color color; + String label; + final int id; + final Color backgroundColor; + final Color textColor; + final bool isPriority; - const StatusLabel({Key key, this.label, this.color}) : super(key: key); + StatusLabel({Key key, this.id, this.label, this.backgroundColor, this.textColor, this.isPriority = false}) : super(key: key); @override Widget build(BuildContext context) { + if (id == 82) label = "High Priority"; + if (id == 81) label = "Low Priority"; + + print("label:$label:$id"); return Container( - padding: EdgeInsets.symmetric(vertical: 2, horizontal: 8), - alignment: Alignment.center, - decoration: BoxDecoration(color: color ?? Colors.green, borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), boxShadow: [AppStyle.boxShadow]), - child: Text( - label ?? "no status", - style: Theme.of(context).textTheme.subtitle2.copyWith( - color: color.computeLuminance() > 0.5 ? AColors.black : Colors.white, - ), - )); + padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 10), + decoration: ShapeDecoration( + color: backgroundColor, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(50), + ), + ), + child: Text(label.toUpperCase(), style: AppTextStyles.overline.copyWith(color: textColor)), + ); + } + + Color getRequestStatusColor1(String status) { + switch (status) { + case "in progress": + return AColors.statusYellowLight; + case "completed": + return AColors.statusGreenLight; + case "high priority": + return AColors.statusRedLight; + case "low priority": + return AColors.statusGreenLight; + case "open": + return AColors.statusBlueLight; + default: + return AColors.statusDefault; + } + } + + Color getRequestStatusTextColor(String status) { + switch (status) { + case "in progress": + return AColors.statusYellow; + case "completed": + return AColors.statusGreen; + case "high priority": + return AColors.statusRed; + case "low priority": + return AColors.statusGreen; + case "open": + return AColors.statusBlue; + default: + return Colors.white; + } + } + + static Color getRequestStatusColor(int id) { + switch (id) { + case 4: + return AColors.deepRed; + case 6: + return AColors.green; + case 5: + return AColors.orange; + case 8: + return AColors.green; + case 9: + return AColors.orange; + default: + return AColors.grey; + } + } + + static Color getGasStatusColor(int id) { + switch (id) { + case 0: + return AColors.orange; + case 1: + return AColors.green; + default: + return AColors.grey; + } + } + + static Color getPriorityStatusColor(int id) { + switch (id) { + case 0: + return AColors.orange; + case 1: + return AColors.green; + default: + return AColors.grey; + } } } diff --git a/lib/views/widgets/requests/service_request_item.dart b/lib/views/widgets/requests/service_request_item.dart index 30fe3768..6faf7340 100644 --- a/lib/views/widgets/requests/service_request_item.dart +++ b/lib/views/widgets/requests/service_request_item.dart @@ -7,6 +7,7 @@ import 'package:test_sa/controllers/providers/api/user_provider.dart'; import 'package:test_sa/controllers/providers/settings/setting_provider.dart'; import 'package:test_sa/extensions/context_extension.dart'; import 'package:test_sa/extensions/int_extensions.dart'; +import 'package:test_sa/extensions/string_extensions.dart'; import 'package:test_sa/extensions/text_extensions.dart'; import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/models/enums/translation_keys.dart'; @@ -36,269 +37,74 @@ class ServiceRequestItem extends StatelessWidget { Color itemColor = index % 2 == 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.onPrimary; Color onItemColor = index % 2 != 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.onPrimary; - return index % 2 == 0 - ? Container( - decoration: ShapeDecoration( - color: Colors.white, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(20), + return Container( + decoration: ShapeDecoration( + color: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(20), + ), + shadows: const [BoxShadow(color: Color(0x07000000), blurRadius: 14, offset: Offset(0, 0), spreadRadius: 0)], + ), + child: Column( + children: [ + Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + StatusLabel( + label: request.priority.name, + id: request.priority.id, + textColor: AColors.getPriorityStatusTextColor(request.priority.id), + backgroundColor: AColors.getPriorityStatusColor(request.priority.id)), + 8.width, + StatusLabel(label: request.statusLabel, textColor: AColors.getRequestStatusTextColor(request.statusValue), backgroundColor: AColors.getRequestStatusColor(request.statusValue)), + 1.width.expanded, + Text(request.date.toServiceRequestCardFormat, textAlign: TextAlign.end, style: AppTextStyles.tinyFont.copyWith(color: const Color(0xFF3B3D4A))), + ], + ), + 8.height, + Text(context.translate(TranslationKeys.serviceRequest), style: AppTextStyles.heading5.copyWith(color: const Color(0xFF3B3D4A))), + Text( + '${_subtitle.assetName}: ${request.deviceEnName}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + Text( + '${_subtitle.assetNumber}: ${request.device.number}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), ), - shadows: const [BoxShadow(color: Color(0x07000000), blurRadius: 14, offset: Offset(0, 0), spreadRadius: 0)], - ), - child: Column( - children: [ - Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 10), - decoration: ShapeDecoration( - color: const Color(0xFFFFDBDC), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(50), - ), - ), - child: Text('HIGH PRIORITY', style: AppTextStyles.overline.copyWith(color: const Color(0xFF8C0409))), - ), - 8.width, - Container( - padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 10), - decoration: ShapeDecoration( - color: const Color(0xFFFFEDBC), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(50), - ), - ), - child: Text('IN PROGRESS', style: AppTextStyles.overline.copyWith(color: const Color(0xFF886300))), - ), - 1.width.expanded, - Text('05 Dec, 2022\n09:30 AM', textAlign: TextAlign.end, style: AppTextStyles.tinyFont.copyWith(color: const Color(0xFF3B3D4A))), - ], - ), - 8.height, - Text(context.translate(TranslationKeys.serviceRequest), style: AppTextStyles.heading5.copyWith(color: const Color(0xFF3B3D4A))), - ], - ).paddingAll(16), - ], - ), - ) - : Padding( - padding: const EdgeInsets.symmetric(vertical: 4), - child: ElevatedButton( - style: ElevatedButton.styleFrom( - padding: EdgeInsets.symmetric(vertical: 8, horizontal: 8), - primary: itemColor, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), - ), + Text( + 'Request Type: ${request.type.name}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), ), - //padding: EdgeInsets.symmetric(vertical: 8,horizontal: 8), - onPressed: () { - onPressed(request); - }, - child: Row( + Text( + 'Request No: ${request.requestCode}', + style: AppTextStyles.bodyText.copyWith(color: Color(0xFF757575)), + ), + 8.height, + Row( + mainAxisSize: MainAxisSize.min, children: [ - //Placeholder(color: onItemColor,fallbackWidth: 80,fallbackHeight: 80,), - _user.type == UsersTypes.normal_user && request.devicePhotos.isEmpty - ? SizedBox.shrink() - : SizedBox( - width: 80, - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - request.devicePhotos?.isEmpty != false - ? SizedBox.shrink() - : Column( - children: [ - SizedBox( - height: 80, - width: 80, - child: ImageLoader( - url: request.devicePhotos.first, - boxFit: BoxFit.cover, - ), - ), - SizedBox( - height: 24, - ), - ], - ), - - _user.type == UsersTypes.engineer - ? Material( - color: onItemColor, - elevation: 6, - shape: CircleBorder(), - child: IconButton( - icon: Icon( - Icons.description, - color: itemColor, - size: 32, - ), - onPressed: () { - Navigator.of(context).push( - MaterialPageRoute( - builder: (_) => CreateServiceReport( - request: request, - )), - ); - }, - ), - ) - : SizedBox.shrink(), - //SizedBox(height: 8,), - ], - ), - ), - SizedBox( - width: 8, - ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - children: [ - Expanded( - child: request.requestCode == null - ? SizedBox.shrink() - : Text( - request.requestCode ?? "-----", - style: Theme.of(context).textTheme.headline6.copyWith(color: onItemColor, fontSize: 16, fontWeight: FontWeight.bold), - ), - ), - request.engineerName == null - ? SizedBox.shrink() - : Text( - request.engineerName ?? "", - style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), - ), - ], - ), - Divider( - color: onItemColor, - ), - Text( - request.deviceNumber, - style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), - ), - Divider( - color: onItemColor, - ), - Row( - children: [ - Expanded( - child: request.deviceModel == null - ? SizedBox.shrink() - : Text( - request.deviceModel ?? "Model not available", - style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), - ), - ), - request.engineerMobile == null - ? SizedBox.shrink() - : Text( - request.engineerMobile, - style: Theme.of(context).textTheme.subtitle1.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), - ), - ], - ), - Divider( - color: onItemColor, - ), - Row( - children: [ - Expanded( - child: request.deviceSerialNumber == null - ? SizedBox.shrink() - : Text( - request.deviceSerialNumber, - style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), - ), - ), - ], - ), - request.deviceEnName == null - ? SizedBox.shrink() - : Row( - children: [ - Expanded( - child: Text( - request.deviceEnName, - style: Theme.of(context).textTheme.subtitle1.copyWith(color: onItemColor, fontSize: 12, fontWeight: FontWeight.normal), - ), - ), - ], - ), - ], - ), - ), - ], - ), - Divider( - color: onItemColor, - ), - Center( - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 8), - child: Text( - request.callComments ?? "No maintenance issue found", - style: Theme.of(context).textTheme.subtitle1.copyWith(color: onItemColor), - textAlign: TextAlign.center, - ), - ), - ), - Divider( - color: onItemColor, - ), - Row( - children: [ - Text( - request.date ?? "Date not available", - style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor), - ), - Spacer(), - StatusLabel(label: request.statusLabel, color: AColors.getRequestStatusColor(request.statusValue)), - ], - ), - request.nextVisitDate == null - ? SizedBox.shrink() - : Column( - children: [ - Divider( - color: onItemColor, - ), - Row( - children: [ - Text( - _subtitle.nextVisitDate, - style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor), - ), - Spacer(), - Text( - DateFormat('EE dd/MM/yyyy').format(request.nextVisitDate), - style: Theme.of(context).textTheme.subtitle2.copyWith(color: onItemColor), - ), - ], - ), - ], - ), - ], - ), + Text( + 'View Details', + style: AppTextStyles.bodyText.copyWith(color: const Color(0xFF4A8DB7)), ), + 4.width, + const Icon( + Icons.arrow_forward, + color: Color(0xFF4A8DB7), + size: 14, + ) ], ), - ), - ); + ], + ).paddingAll(16).onPress(() { + onPressed(request); + }), + ], + ), + ); } }