diff --git a/lib/controllers/providers/api/service_requests_provider.dart b/lib/controllers/providers/api/service_requests_provider.dart index 9c18b46d..41c75d37 100644 --- a/lib/controllers/providers/api/service_requests_provider.dart +++ b/lib/controllers/providers/api/service_requests_provider.dart @@ -461,42 +461,28 @@ class ServiceRequestsProvider extends ChangeNotifier { } } - Future updateServiceReport({ - @required ServiceReport report, - String host, - User user, - ServiceRequest request, - }) async { + Future updateServiceReport(BuildContext context, {@required ServiceReport report}) async { Response response; - //Map body = report.toMap(request); - // body["uid"] = user.id; - // body["token"] = user.token; - // body["job_id"] = request.id; - // body["report_id"] = request.reportID; - // try { + report.callRequest = CallRequest(id: report.callRequest.id); Map body = report.toJson(); - - /// todo [zaid] : don't forget to add [request] data to [body] - // Map body = report.toMap(request); - // body["uid"] = user.id; - // body["token"] = user.token; - response = await ApiManager.instance.put(URLs.updateServiceReport, body: body); - // response = await post( - // Uri.parse( - // host+URLs.updateServiceReport), - // body: body, - // ); - // stateCode = response.statusCode; - - if (response.statusCode >= 200 && response.statusCode < 300) { - reset(); - notifyListeners(); + try { + showDialog(context: context, barrierDismissible: false, builder: (context) => const AppLazyLoading()); + response = await ApiManager.instance.put(URLs.updateServiceReport, body: body); + if (response.statusCode >= 200 && response.statusCode < 300) { + reset(); + notifyListeners(); + Fluttertoast.showToast(msg: context.translation.successfulRequestMessage); + Navigator.of(context).pop(); + } else { + Fluttertoast.showToast(msg: "${context.translation.failedToCompleteRequest}"); + } + Navigator.of(context).pop(); + return response.statusCode; + } catch (e) { + print(e); + Navigator.of(context).pop(); + return -1; } - return response.statusCode; - // } catch (error) { - // print(error); - // return -1; - // } } Future updateWorkOrderDetails({@required SearchWorkOrder workOrder}) async { @@ -560,28 +546,20 @@ class ServiceRequestsProvider extends ChangeNotifier { } } - Future getSingleServiceReport({ - @required int reportId, - @required String host, - @required User user, - @required AppLocalizations subtitle, - }) async { + Future getSingleServiceReport(BuildContext context, {@required int reportId}) async { Response response; try { - response = await ApiManager.instance.get( - URLs.getServiceReport + "?workOrderId=$reportId", - ); + response = await ApiManager.instance.get(URLs.getServiceReport + "?workOrderId=$reportId"); } catch (error) { - throw (HttpStatusManger.getStatusMessage(status: -1, subtitle: subtitle)); + throw (context.translation.failedToCompleteRequest); } // If the call to the server was successful, parse the JSON. if (response.statusCode >= 200 && response.statusCode < 300) { // If the call to the server was successful, parse the JSON. - /// todo [zaid]: check [reportId] below - return ServiceReport.fromJson(json.decode(response.body)["data"] /*, reportId*/); + return ServiceReport.fromJson(json.decode(response.body)["data"]); } else { - throw (HttpStatusManger.getStatusMessage(status: response.statusCode, subtitle: subtitle)); + throw (("${context.translation.failedToCompleteRequest} ${jsonDecode(response.body)["message"]}")); } } diff --git a/lib/l10n/app_ar.arb b/lib/l10n/app_ar.arb index 3a197653..20102d21 100644 --- a/lib/l10n/app_ar.arb +++ b/lib/l10n/app_ar.arb @@ -295,5 +295,6 @@ "assistantEmployee" : "موظف مساعد", "assignAssistant" : "تعيين مساعد", "partNo" : "الجزء رقم", - "engSign" : "توقيع المهندس" + "engSign" : "توقيع المهندس", + "updateWorkOrder" : "تعديل طلب العمل" } \ No newline at end of file diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 77f11ce2..5233fb33 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -299,5 +299,6 @@ "assistantEmployee" : "Assistant Employee", "assignAssistant" : "Assign Assistant", "partNo" : "Part No.", - "engSign" : "Engineer Signature" + "engSign" : "Engineer Signature", + "updateWorkOrder" : "Update Work Order" } \ No newline at end of file diff --git a/lib/views/pages/user/requests/update_service_request_page.dart b/lib/views/pages/user/requests/update_service_request_page.dart index 9af6081f..d7e7a395 100644 --- a/lib/views/pages/user/requests/update_service_request_page.dart +++ b/lib/views/pages/user/requests/update_service_request_page.dart @@ -140,7 +140,7 @@ class _UpdateServiceRequestPageState extends State { ], ), ).expanded, - AppFilledButton(onPressed: _submit, label: context.translation.submitRequest), + AppFilledButton(onPressed: _submit, label: context.translation.updateRequest), ], ), ).paddingOnly(start: 16, end: 16, bottom: 24, top: 16), diff --git a/lib/views/pages/user/requests/work_order/create_service_report.dart b/lib/views/pages/user/requests/work_order/create_service_report.dart index d1e5956d..4383e6ff 100644 --- a/lib/views/pages/user/requests/work_order/create_service_report.dart +++ b/lib/views/pages/user/requests/work_order/create_service_report.dart @@ -208,6 +208,7 @@ class _CreateServiceReportState extends State with TickerPr ), 8.height, MultiFilesPicker(label: context.translation.attachImage, files: _files), + 8.height, ESignature( title: context.translation.engSign, oldSignature: _serviceReport.engSignature, diff --git a/lib/views/pages/user/requests/work_order/edit_service_report.dart b/lib/views/pages/user/requests/work_order/edit_service_report.dart index 8915d49e..34d2c562 100644 --- a/lib/views/pages/user/requests/work_order/edit_service_report.dart +++ b/lib/views/pages/user/requests/work_order/edit_service_report.dart @@ -1,33 +1,36 @@ +import 'dart:convert'; import 'dart:io'; import 'package:flutter/material.dart'; -import 'package:fluttertoast/fluttertoast.dart'; import 'package:provider/provider.dart'; -import 'package:test_sa/controllers/api_routes/http_status_manger.dart'; import 'package:test_sa/controllers/providers/api/service_requests_provider.dart'; -import 'package:test_sa/controllers/providers/api/status_drop_down/report/service_report_last_calls_provider.dart'; import 'package:test_sa/controllers/providers/api/status_drop_down/report/service_types_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/controllers/validator/validator.dart'; import 'package:test_sa/extensions/context_extension.dart'; +import 'package:test_sa/extensions/int_extensions.dart'; +import 'package:test_sa/extensions/text_extensions.dart'; +import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/models/service_request/service_report.dart'; import 'package:test_sa/models/service_request/service_request.dart'; -import 'package:test_sa/views/app_style/colors.dart'; -import 'package:test_sa/views/app_style/sizing.dart'; -import 'package:test_sa/views/widgets/app_text_form_field.dart'; -import 'package:test_sa/views/widgets/buttons/app_back_button.dart'; -import 'package:test_sa/views/widgets/buttons/app_button.dart'; import 'package:test_sa/views/widgets/loaders/loading_manager.dart'; -import 'package:test_sa/views/widgets/status/report/service_report_equipment_status.dart'; -import 'package:test_sa/views/widgets/status/report/service_report_fault_description.dart'; import 'package:test_sa/views/widgets/status/report/service_report_last_call.dart'; -import 'package:test_sa/views/widgets/status/report/service_report_reasons.dart'; -import 'package:test_sa/views/widgets/status/report/service_report_repair_location.dart'; -import 'package:test_sa/views/widgets/titles/app_sub_title.dart'; +import '../../../../../attachment.dart'; +import '../../../../../models/lookup.dart'; +import '../../../../../models/service_request/spare_parts.dart'; import '../../../../../models/service_request/wo_call_request.dart'; +import '../../../../../new_views/common_widgets/app_filled_button.dart'; +import '../../../../../new_views/common_widgets/app_text_form_field.dart'; +import '../../../../../new_views/common_widgets/default_app_bar.dart'; +import '../../../../../new_views/common_widgets/single_item_drop_down_menu.dart'; +import '../../../../../providers/loading_list_notifier.dart'; +import '../../../../../providers/work_order/reason_provider.dart'; +import '../../../../../providers/work_order/service_type_provider.dart'; +import '../../../../widgets/date_and_time/date_picker.dart'; +import '../../../../widgets/e_signature/e_signature.dart'; import '../../../../widgets/images/multi_image_picker.dart'; +import '../../../../widgets/status/report/service_report_assistant_employee_menu.dart'; class EditServiceReport extends StatefulWidget { static final String id = "/edit-service-report"; @@ -44,35 +47,31 @@ class _EditServiceReportState extends State with TickerProvid UserProvider _userProvider; SettingProvider _settingProvider; ServiceRequestsProvider _serviceRequestsProvider; - - bool _validate = false; + List _spareParts = []; ServiceReport _serviceReport; bool _isLoading = false; - bool _showCommentField = false; - - List _images = []; + List _files = []; final GlobalKey _formKey = GlobalKey(); final GlobalKey _scaffoldKey = GlobalKey(); - TextEditingController _faultController = TextEditingController(); - TextEditingController _workPreformedController = TextEditingController(); - + final TextEditingController _faultController = TextEditingController(); + final TextEditingController _workPreformedController = TextEditingController(); ServiceStatusProvider _assetTypeProvider; - CallRequest _callRequestForWorkOrder; @override void initState() { _serviceReport = widget.report; - // _images = widget.report?.files?.map((e) => File(e))?.toList(); + _files = widget.report?.attachmentsWorkOrder?.map((e) => File(e.name))?.toList(); + _spareParts = _serviceReport.sparePartsWorkOrders.map((e) => e.sparePart).toList(); super.initState(); } void getRequestForWorkOrder() async { _isLoading = true; setState(() {}); - _callRequestForWorkOrder = await _serviceRequestsProvider.getCallRequestForWorkOrder(callId: widget.request.id); - // _serviceReport.engineer = Engineer.fromJson(_callRequestForWorkOrder?.assignedEmployee?.toJson()); - await _assetTypeProvider.getTypes(user: _userProvider.user, host: _settingProvider.host); + _callRequestForWorkOrder = await _serviceRequestsProvider?.getCallRequestForWorkOrder(callId: widget.request.id); + _serviceReport.assignedEmployee = _callRequestForWorkOrder?.assignedEmployee; + await _assetTypeProvider?.getTypes(user: _userProvider.user, host: _settingProvider.host); _isLoading = false; setState(() {}); } @@ -89,18 +88,14 @@ class _EditServiceReportState extends State with TickerProvid _userProvider = Provider.of(context); _settingProvider = Provider.of(context); _serviceRequestsProvider = Provider.of(context); - _assetTypeProvider = Provider.of(context); if (_callRequestForWorkOrder == null) { getRequestForWorkOrder(); } - _serviceReport.assetType = _assetTypeProvider.statuses?.firstWhere( - (element) => element.value == _callRequestForWorkOrder?.assetType, - orElse: () => null, - ); - + _serviceReport.assetType = _assetTypeProvider.statuses?.firstWhere((element) => element.value == _callRequestForWorkOrder?.assetType, orElse: () => null); return Scaffold( key: _scaffoldKey, + appBar: DefaultAppBar(title: context.translation.updateWorkOrder), body: SafeArea( child: LoadingManager( isLoading: _isLoading, @@ -109,990 +104,143 @@ class _EditServiceReportState extends State with TickerProvid onRefresh: () async {}, child: Form( key: _formKey, - child: Stack( + child: Column( children: [ - ListView( - padding: const EdgeInsets.all(16), - children: [ - const SizedBox(height: 16), - Center( - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Text( - context.translation.editServiceReport, - style: Theme.of(context).textTheme.headline5.copyWith(color: AColors.cyan, fontSize: 28, fontWeight: FontWeight.bold), - ), + SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Card( + child: Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + widget.request.hospitalName.heading5(context), + 8.height, + "${context.translation.assetNo}: ${widget.request.deviceNumber}".bodyText(context), + "${context.translation.callId}: ${widget.request.requestCode}".bodyText(context), + ], + ).paddingAll(16), ), - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle("Caller Info"), - const SizedBox(height: 8), - Container( - width: double.infinity, - padding: const EdgeInsets.all(16), - margin: const EdgeInsets.symmetric(vertical: 16), - decoration: BoxDecoration(color: AColors.grey, borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), boxShadow: const [ - BoxShadow( - color: AColors.grey, - offset: Offset(0, -1), - ) - ]), - child: Wrap( - direction: Axis.vertical, - spacing: 10, - children: [ - ASubTitle( - "${context.translation.callId}: ${widget.request.requestCode}", - font: 14, - ), - ASubTitle( - "${context.translation.assetNumber}: ${widget.request.deviceNumber}", - font: 14, - ), - widget.request.deviceSerialNumber == null - ? const SizedBox() - : ASubTitle( - "${context.translation.deviceSN}: ${widget.request.deviceSerialNumber}", - font: 14, - ), - Text( - "${context.translation.customer}: ${widget.request.hospitalName}", - style: Theme.of(context).textTheme.subtitle1.copyWith( - fontWeight: FontWeight.bold, - fontSize: 12, - ), - textScaleFactor: AppStyle.getScaleFactor(context), - ) - ], - ), - ), - const SizedBox(height: 8), - ASubTitle("Work Order Details"), - const SizedBox(height: 8), - Container( - width: double.infinity, - padding: const EdgeInsets.all(16), - margin: const EdgeInsets.symmetric(vertical: 16), - decoration: BoxDecoration(color: AColors.grey, borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), boxShadow: const [ - BoxShadow( - color: AColors.grey, - offset: Offset(0, -1), - ) - ]), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // Report type and Reasons - // Row( - // children: [ - // // Report Status - // // Expanded( - // // child: Column( - // // crossAxisAlignment: CrossAxisAlignment.start, - // // children: [ - // // ASubTitle(context.translation.reportType), - // // _validate && _serviceReport.type == null - // // ? ASubTitle( - // // context.translation.requiredWord, - // // color: Colors.red, - // // ) - // // : const SizedBox.shrink(), - // // const SizedBox( - // // height: 4, - // // ), - // // ServiceReportTypeMenu( - // // initialValue: _serviceReport.type, - // // onSelect: (status) { - // // _serviceReport.type = status; - // // }, - // // ), - // // ], - // // ), - // // ), - // // const SizedBox( - // // width: 8, - // // ), - // // visit date - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(context.translation.visitDate), - // _validate && _serviceReport.visitDate == null - // ? ASubTitle( - // context.translation.requiredWord, - // color: Colors.red, - // ) - // : const SizedBox.shrink(), - // Row( - // children: [ - // Expanded( - // child: ADatePicker( - // date: _serviceReport.visitDate, - // from: DateTime.now().subtract(const Duration(days: 365)), - // to: DateTime.now().add(const Duration(days: 365)), - // onDatePicker: (date) { - // _serviceReport.visitDate = date; - // setState(() {}); - // }, - // ), - // ), - // ], - // ), - // ], - // ), - // ), - // ], - // ), - // const SizedBox( - // height: 8, - // ), - // device sn - // Visibility( - // visible: widget.request.deviceSerialNumber == null, - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(context.translation.deviceSN), - // _validate && _serviceReport.device?.id == null - // ? ASubTitle( - // context.translation.requiredWord, - // color: Colors.red, - // ) - // : const SizedBox.shrink(), - // AutoCompleteDeviceField( - // hospitalId: widget.request.hospitalId, - // initialValue: _serviceReport.device, - // onPick: (id) { - // _serviceReport.device.id = id; - // }, - // ), - // const SizedBox(height: 8), - // ], - // ), - // ), - const SizedBox(height: 8), - ASubTitle(context.translation.assetType), - _validate && _serviceReport.assetType == null - ? ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ) - : const SizedBox.shrink(), - const SizedBox( - height: 4, - ), - LoadingManager( - isLoading: _assetTypeProvider.isLoading, - isFailedLoading: _assetTypeProvider.statuses == null, - stateCode: _assetTypeProvider.stateCode, - onRefresh: () async { - _assetTypeProvider.reset(); - await _assetTypeProvider.getTypes(user: _userProvider.user, host: _settingProvider.host); - _serviceReport?.assetType = _assetTypeProvider.statuses?.firstWhere( - (element) => element.value == _callRequestForWorkOrder.assetType, - orElse: () => null, - ); - }, - child: ATextFormField( - initialValue: _serviceReport?.assetType?.name ?? "NULL", - textAlign: TextAlign.center, - enable: false, - style: Theme.of(context).textTheme.titleMedium, - ), - ), - // ServiceAssetTypeMenu( - // initialValue: _serviceReport.assetType, - // onSelect: (status) { - // _serviceReport.assetType = status; - // }, - // ), - const SizedBox( - height: 8, - ), - Row( - children: [ - // report status - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - // ASubTitle(context.translation.reportStatus), - ASubTitle("Equipment Status"), - _validate && _serviceReport.equipmentStatus == null - ? ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ) - : const SizedBox.shrink(), - const SizedBox( - height: 4, - ), - // ServiceReportStatusMenu( - // report: _serviceReport, - // request: widget.request, - // onSelect: (status) { - // _serviceReport.status = status; - // }, - // ), - ServiceReportEquipmentStatusMenu( - report: _serviceReport, - request: widget.request, - onSelect: (status) { - _serviceReport.equipmentStatus = status; - }, - ) - ], - ), - ), - const SizedBox( - width: 8, - ), - // Provider.of(context).isLoading == null - // ? const SizedBox.shrink(): - // Call's last Situation - Consumer( - builder: (_, provider, __) { - if (provider.isLoading == null) return const SizedBox.shrink(); - return Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(context.translation.callLastSituation), - _validate && _serviceReport.calllastSituation == null - ? ASubTitle( - context.translation.requiredWord, - color: Colors.red, - ) - : const SizedBox.shrink(), - const SizedBox(height: 4), - ServiceReportLastCallsMenu( - report: _serviceReport, - onSelect: (status) { - if (status?.value == 12 || _serviceReport.calllastSituation?.value == 12) { - _serviceReport.calllastSituation = status; - setState(() {}); - } else { - _serviceReport.calllastSituation = status; - setState(() {}); - } - }, - ), - ], - ), - ); - }, - ), - ], - ), - const SizedBox( - height: 8, - ), - const ASubTitle("Return to Service"), - // Row( - // children: [ - // Expanded( - // child: ADatePicker( - // date: _serviceReport.returnToService, - // from: DateTime.now().subtract(const Duration(days: 365)), - // to: DateTime.now().add(const Duration(days: 365)), - // onDatePicker: (date) { - // _serviceReport.returnToService = date; - // setState(() {}); - // }, - // ), - // ), - // ], - // ), - if (_serviceReport?.calllastSituation?.value == 2) - Column( - children: [ - const SizedBox( - height: 8, - ), - ATextFormField( - initialValue: _serviceReport?.reviewComment, - hintText: "Vendor Name", - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.titleMedium, - textInputType: TextInputType.multiline, - onSaved: (value) { - _serviceReport.reviewComment = value; - }, - ), - const SizedBox( - height: 8, - ), - ATextFormField( - initialValue: _serviceReport?.reviewComment, - hintText: "Vendor Engineer", - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.titleMedium, - textInputType: TextInputType.multiline, - onSaved: (value) { - _serviceReport.reviewComment = value; - }, - ), - ], - ), - if (_showCommentField) - const SizedBox( - height: 8, - ), - if (_showCommentField) - ATextFormField( - initialValue: _serviceReport?.reviewComment, - hintText: "Review Comment", - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.titleMedium, - textInputType: TextInputType.multiline, - onSaved: (value) { - _serviceReport.reviewComment = value; - }, - ), - - SizedBox( - height: 8 * AppStyle.getScaleFactor(context), - ), - // const ASubTitle("Assign Employee"), - // const SizedBox( - // height: 8, - // ), - // _validate && _serviceReport.engineer == null - // ? ASubTitle( - // context.translation.requiredWord, - // color: Colors.red, - // ) - // : const SizedBox.shrink(), - // const SizedBox( - // height: 4, - // ), - // EngineersMenu( - // initialValue: _serviceReport.engineer, - // onSelect: (engineer) { - // _serviceReport.engineer = engineer; - // }, - // ), - // const SizedBox( - // height: 8, - // ), - // Report status and Service Type - // Row( - // children: [ - // // report status - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(context.translation.reportStatus), - // _validate && _serviceReport.equipmentStatus == null - // ? ASubTitle( - // context.translation.requiredWord, - // color: Colors.red, - // ) - // : const SizedBox.shrink(), - // const SizedBox( - // height: 4, - // ), - // ServiceReportStatusMenu( - // report: _serviceReport, - // request: widget.request, - // onSelect: (status) { - // _serviceReport.equipmentStatus = status; - // }, - // ), - // ], - // ), - // ), - // const SizedBox( - // width: 8, - // ), - // Consumer( - // builder: (_, provider, __) { - // if (provider.isLoading == null) return const SizedBox.shrink(); - // return Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(context.translation.callLastSituation), - // _validate && _serviceReport.callLastSituation == null - // ? ASubTitle( - // context.translation.requiredWord, - // color: Colors.red, - // ) - // : const SizedBox.shrink(), - // const SizedBox( - // height: 4, - // ), - // ServiceReportLastCallsMenu( - // report: _serviceReport, - // onSelect: (status) { - // if (status?.value == 12 || _serviceReport.callLastSituation?.value == 12) { - // _serviceReport.callLastSituation = status; - // setState(() {}); - // } else { - // _serviceReport.callLastSituation = status; - // } - // }, - // ), - // ], - // ), - // ); - // }, - // ), - // ], - // ), - const SizedBox( - height: 8, - ), - // invoice number & code - _serviceReport.calllastSituation?.value != 12 - ? const SizedBox.shrink() - : Row( - children: [ - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(context.translation.invoiceNumber), - // const SizedBox( - // height: 8, - // ), - // ATextFormField( - // initialValue: _serviceReport?.invoiceNumber, - // textAlign: TextAlign.center, - // style: Theme.of(context).textTheme.subtitle1, - // validator: (value) => Validator.hasValue(value) ? null : context.translation.requiredWord, - // textInputType: TextInputType.number, - // onSaved: (value) { - // _serviceReport.invoiceNumber = value; - // }, - // ), - // ], - // ), - // ), - const SizedBox( - width: 8, - ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - ASubTitle(context.translation.invoiceCode), - const SizedBox( - height: 4, - ), - // ATextFormField( - // initialValue: _serviceReport?.invoiceCode, - // textAlign: TextAlign.center, - // style: Theme.of(context).textTheme.subtitle1, - // validator: (value) => Validator.hasValue(value) ? null : context.translation.requiredWord, - // textInputType: TextInputType.text, - // onSaved: (value) { - // _serviceReport.invoiceCode = value; - // }, - // ), - ], - ), - ), - ], - ), - - // const SizedBox(height: 8,), - // Row( - // children: [ - // ASubTitle(context.translation.faultDescription), - // Expanded( - // child: SizedBox( - // height: 32 * AppStyle.getScaleFactor(context), - // child: SpeechToTextButton( - // controller: _faultController, - // mini: true, - // ), - // ), - // ), - // ], - // ), - // const SizedBox(height: 4,), - // ATextFormField( - // initialValue: _serviceReport?.faultDescriptionId, - // textAlign: TextAlign.center, - // controller: _faultController, - // style: Theme.of(context).textTheme.subtitle1, - // validator: (value) => - // Validator.hasValue(value) - // ? null : context.translation.requiredWord, - // textInputType: TextInputType.multiline, - // onSaved: (value){ - // _serviceReport.faultDescriptionId = value; - // }, - // ), - // const SizedBox(height: 8,), - // Row( - // children: [ - // ASubTitle(context.translation.workPreformed), - // Expanded( - // child: SizedBox( - // height: 32 * AppStyle.getScaleFactor(context), - // child: SpeechToTextButton( - // controller: _workPreformedController, - // mini: true, - // ), - // ), - // ), - // ], - // ), - // const SizedBox(height: 4,), - // ATextFormField( - // initialValue: _serviceReport?.workPreformed, - // textAlign: TextAlign.center, - // controller: _workPreformedController, - // style: Theme.of(context).textTheme.subtitle1, - // validator: (value) => - // Validator.hasValue(value) - // ? null : context.translation.requiredWord, - // textInputType: TextInputType.multiline, - // onSaved: (value){ - // _serviceReport.workPreformed = value; - // }, - // ), - // const SizedBox(height: 8,), - const SizedBox(height: 8), - ASubTitle(context.translation.workingHours), - const SizedBox(height: 8), - // Row( - // children: [ - // Expanded( - // child: AppTimer( - // timer: _serviceReport.timer, - // enabled: false, - // // onChange: (timer) async { - // // _serviceReport.timer = timer; - // // _serviceReport.workingHours = num.tryParse((((timer?.durationInSecond ?? 0) / 60) / 60)?.toStringAsFixed(2) ?? "0"); - // // return true; - // // }, - // ), - // ), - // ], - // ), - const SizedBox(height: 16), - if (_showCommentField) - const SizedBox( - height: 8, - ), - if (_showCommentField) - ATextFormField( - initialValue: _serviceReport?.reviewComment, - hintText: "Review Comment", - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.titleMedium, - textInputType: TextInputType.multiline, - onSaved: (value) { - _serviceReport.reviewComment = value; - }, - ), - SizedBox( - height: 8 * AppStyle.getScaleFactor(context), - ), - const SizedBox(height: 8), - ASubTitle(context.translation.faultDescription), - const SizedBox( - height: 4, - ), - ServiceReportFaultDescription( - requestId: widget.request?.id, - initialValue: _serviceReport.faultDescription, - onSelect: (status) { - _serviceReport.faultDescription = status; - WidgetsBinding.instance.addPostFrameCallback((timeStamp) { - if (mounted) setState(() {}); - }); - }, - ), - const SizedBox(height: 8), - const ASubTitle("Solutions"), - const SizedBox(height: 4), - ATextFormField( - initialValue: "_serviceReport?.workPreformed", - textAlign: TextAlign.center, - enable: false, - hintText: _serviceReport.faultDescription?.workPerformed ?? "", - controller: _workPreformedController, - style: Theme.of(context).textTheme.subtitle1, - validator: (value) => Validator.hasValue(value) ? null : context.translation.requiredWord, - textInputType: TextInputType.multiline, - onSaved: (value) { - // _serviceReport.workPreformed = value; - }, - ), - const SizedBox(height: 4), - ASubTitle("Failure Reason"), - const SizedBox( - height: 4, - ), - ServiceReportReasonsMenu( - initialValue: _serviceReport.reason, - onSelect: (status) { - _serviceReport.reason = status; - }, - ), - const SizedBox( - height: 8, - ), - ASubTitle(context.translation.attachImage), - const SizedBox( - height: 4, - ), - MultiFilesPicker( - label: "", - files: _images, - ), - // AMiniOneImagePicker( - // //error: _validate && _serviceReport.image == null, - // image: _image, - // onPick: (image) { - // _image = image; - // _serviceReport.image = base64Encode(image.readAsBytesSync()); - // }, - // ), - const SizedBox( - height: 8, - ), - const SizedBox(height: 8), - ASubTitle(context.translation.repairLocation), - const SizedBox(height: 4), - ServiceReportRepairLocation( - initialValue: _serviceReport.repairLocation, - onSelect: (status) { - _serviceReport.repairLocation = status; - }, - ), - const SizedBox(height: 16), - ASubTitle("Travel Expenses"), - const SizedBox( - height: 4, - ), - ATextFormField( - initialValue: " _serviceReport?.travelingExpense?.toString()", - hintText: context.translation.travelingExpense, - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.titleMedium, - textInputType: TextInputType.number, - onSaved: (value) { - // if (value != null && value.isEmpty) { - // _serviceReport.travelingExpense = num.tryParse(_serviceReport?.travelingExpense?.toString() ?? "") ?? 0; - // } else - // _serviceReport.travelingExpense = num.tryParse(value) ?? 0; - }, - ), - - const SizedBox(height: 8), - ASubTitle(context.translation.travelingHours), - const SizedBox(height: 4), - ATextFormField( - initialValue: _serviceReport?.travelingHours?.toString(), - textAlign: TextAlign.center, - hintText: "i.e 3, 3.5, 4", - style: Theme.of(context).textTheme.subtitle1, - // validator: (value) => - // Validator.isNumeric(value) - // ? null : context.translation.requiredWord, - textInputType: TextInputType.number, - onSaved: (value) { - _serviceReport.travelingHours = double.tryParse(value) ?? 0.0; - }, - ), - // Traveling Hours & Working Hours - // Row( - // children: [ - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(context.translation.workingHours), - // const SizedBox( - // height: 8, - // ), - // Row( - // children: [ - // Expanded( - // child: AppTimer( - // timer: _serviceReport.timer, - // onChange: (timer) async { - // _serviceReport.timer = timer; - // return true; - // }, - // ), - // ), - // ], - // ), - // // ATextFormField( - // // initialValue: _serviceReport?.workHours, - // // textAlign: TextAlign.center, - // // hintText: "i.e 3, 3.5, 4", - // // style: Theme.of(context).textTheme.subtitle1, - // // validator: (value) => - // // Validator.isNumeric(value) - // // ? null : context.translation.requiredWord, - // // textInputType: TextInputType.number, - // // onSaved: (value){ - // // _serviceReport.workHours = value; - // // }, - // // ), - // ], - // ), - // ), - // // const SizedBox(width: 8,), - // // Expanded( - // // child: Column( - // // crossAxisAlignment: CrossAxisAlignment.start, - // // children: [ - // // ASubTitle(context.translation.travelingHours), - // // const SizedBox(height: 4,), - // // ATextFormField( - // // initialValue: _serviceReport?.travelingHours, - // // textAlign: TextAlign.center, - // // hintText: "i.e 3, 3.5, 4", - // // style: Theme.of(context).textTheme.subtitle1, - // // validator: (value) => - // // Validator.isNumeric(value) - // // ? null : context.translation.requiredWord, - // // textInputType: TextInputType.number, - // // onSaved: (value){ - // // _serviceReport.travelingHours = value; - // // }, - // // ), - // // ], - // // ), - // // ), - // ], - // ), - // const SizedBox( - // height: 8, - // ), - // Operating Hours and Job Sheet Number - // Row( - // children: [ - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(context.translation.operatingHours), - // const SizedBox(height: 4,), - // ATextFormField( - // initialValue: _serviceReport?.operatingHours, - // textAlign: TextAlign.center, - // hintText: "i.e 3, 3.5, 4", - // style: Theme.of(context).textTheme.subtitle1, - // validator: (value) => - // Validator.isNumeric(value) - // ? null : context.translation.requiredWord, - // textInputType: TextInputType.number, - // onSaved: (value){ - // _serviceReport.operatingHours = value; - // }, - // ), - // ], - // ), - // ), - // const SizedBox(width: 8,), - // Expanded( - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(context.translation.jobSheetNumber), - // const SizedBox(height: 4,), - // ATextFormField( - // initialValue: _serviceReport?.jobSheetNumber, - // textAlign: TextAlign.center, - // style: Theme.of(context).textTheme.subtitle1, - // textInputType: TextInputType.name, - // onSaved: (value){ - // _serviceReport.jobSheetNumber = value; - // }, - // ), - // ], - // ), - // ), - // ], - // ), - //const SizedBox(height: 8,), - - const SizedBox(height: 8), - const ASubTitle("Technical comment"), - const SizedBox(height: 4), - ATextFormField( - initialValue: _serviceReport?.comment, - hintText: "Technical Comment", - textAlign: TextAlign.center, - style: Theme.of(context).textTheme.titleMedium, - textInputType: TextInputType.multiline, - onSaved: (value) { - _serviceReport.comment = value; - }, - ), - const SizedBox(height: 8), - const ASubTitle("Nurse Signature"), - // ESignature( - // oldSignature: _serviceReport.signatureNurse, - // newSignature: _serviceReport.localNurseSignature, - // onSaved: (signature) { - // if (signature == null || signature.isEmpty) { - // return; - // } - // _serviceReport.localNurseSignature = signature; - // _serviceReport.signatureNurse = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; - // }, - // ), - // const SizedBox( - // height: 8, - // ), - // const ASubTitle("Engineer Signature"), - // ESignature( - // oldSignature: _serviceReport.signatureEngineer, - // newSignature: _serviceReport.localNurseSignature, - // onSaved: (signature) { - // if (signature == null || signature.isEmpty) { - // return; - // } - // _serviceReport.localNurseSignature = signature; - // _serviceReport.signatureEngineer = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}"; - // }, - // ), - const SizedBox( - height: 8, - ), - // Part Number and Quantity - ], - ), - ), - ], - ), - ASubTitle("Spare Parts"), - Container( - width: double.infinity, - padding: const EdgeInsets.all(16), - margin: const EdgeInsets.symmetric(vertical: 16), - decoration: BoxDecoration(color: AColors.grey, borderRadius: BorderRadius.circular(AppStyle.getBorderRadius(context)), boxShadow: [ - BoxShadow( - color: AColors.grey, - offset: Offset(0, -1), - ) - ]), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - // Row( - // children: [ - // Expanded( - // flex: 3, - // child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - // children: [ - // ASubTitle(context.translation.partNumberName), - // _validate && _serviceReport.parts == null - // ? ASubTitle( - // context.translation.requiredWord, - // color: Colors.red, - // ) - // : const SizedBox.shrink(), - // const SizedBox( - // height: 4, - // ), - // AutoCompletePartsField( - // assetId: _serviceReport?.device?.id, - // onPick: (part) { - // _serviceReport.parts.add(part); - // setState(() {}); - // }, - // ), - // ], - // ), - // ), - // ], - // ), - SizedBox( - height: 8 * AppStyle.getScaleFactor(context), - ), - Row( - children: [ - Expanded(flex: 3, child: Text(context.translation.number)), - Expanded(flex: 1, child: Text(context.translation.quantity)), - ], - ), - // Column( - // children: List.generate(_serviceReport.parts.length, (index) { - // Part _part = _serviceReport.parts[index]; - // return PartItem( - // part: _part, - // onDelete: (part) { - // _serviceReport.parts.remove(part); - // setState(() {}); - // }, - // ); - // }), - // ), - const SizedBox( - height: 16, - ), - ], + 8.height, + ADatePicker( + label: context.translation.visitDate, + date: DateTime.tryParse(_serviceReport.visitDate ?? ""), + onDatePicker: (date) { + _serviceReport.visitDate = date?.toIso8601String(); + // setState(() {}); + }, ), - ), - AButton( - text: context.translation.update, - onPressed: () async { - if (_serviceReport?.workingHours == null) { - await Fluttertoast.showToast(msg: "Working Hours Timer Isn't Started"); - return; - } - _validate = true; - // if (!_formKey.currentState.validate()) { - // setState(() {}); - // return; - // } - // print("jere124"); - // if (!_serviceReport.validate()) { - // setState(() {}); - // return; - // } - // print("jere14"); - _formKey.currentState.save(); - - _isLoading = true; - setState(() {}); - // _serviceReport.files = _images.map((e) => _isLocalUrl(e.path) ? "${e.path.split("/").last}|${base64Encode(e.readAsBytesSync())}" : e.path).toList(); - int status = await _serviceRequestsProvider.updateServiceReport(user: _userProvider.user, host: _settingProvider.host, report: _serviceReport, request: widget.request); - _isLoading = false; - setState(() {}); - if (status >= 200 && status < 300) { - Fluttertoast.showToast( - msg: context.translation.successfulRequestMessage, - ); - Navigator.of(context).pop(); - Navigator.of(context).pop(); - } else { - String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: context.translation); - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: Text(errorMessage), - )); - } - }, - ), - ], + 8.height, + AppTextFormField( + labelText: context.translation.workingHours, + textInputType: TextInputType.number, + initialValue: _serviceReport.workingHours?.toString(), + onSaved: (text) { + _serviceReport.workingHours = num.tryParse(text ?? ""); + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.reason, + initialValue: _serviceReport.reason, + onSelect: (value) { + _serviceReport.reason = value; + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.serviceType, + onSelect: (value) {}, + ), + 8.height, + ServiceReportLastCallsMenu( + report: _serviceReport, + title: context.translation.callLastSituation, + parentId: widget.request.id, + onSelect: (status) { + _serviceReport.calllastSituation = status; + }, + ), + 8.height, + ServiceReportAssistantEmployeeMenu( + title: context.translation.assignAssistant, + assetId: _serviceReport.callRequest?.asset?.id, + initialValue: (_serviceReport.assistantEmployees?.isNotEmpty ?? false) ? _serviceReport.assistantEmployees?.first : null, + onSelect: (employee) { + _serviceReport.assistantEmployees = [employee.copyWith(id: 0)]; + }, + ), + 8.height, + SingleItemDropDownMenu( + context: context, + title: context.translation.partNo, + staticData: _spareParts, + initialValue: (_serviceReport.sparePartsWorkOrders?.isNotEmpty ?? false) ? _serviceReport.sparePartsWorkOrders.first.sparePart : null, + onSelect: (part) { + _serviceReport.sparePartsWorkOrders.clear(); + _serviceReport.sparePartsWorkOrders.add(SparePartsWorkOrders(id: 0, sparePart: part, qty: 0)); + // setState(() {}); + }, + ), + 8.height, + AppTextFormField( + labelText: context.translation.quantity, + textInputType: TextInputType.number, + enable: _serviceReport.sparePartsWorkOrders.isNotEmpty, + initialValue: (_serviceReport.sparePartsWorkOrders?.isNotEmpty ?? false) ? _serviceReport.sparePartsWorkOrders.first.qty?.toString() : null, + onSaved: (text) { + if (_serviceReport.sparePartsWorkOrders?.isNotEmpty ?? false) { + _serviceReport.sparePartsWorkOrders.first.qty = num.tryParse(text ?? ""); + } + }, + ), + 8.height, + MultiFilesPicker(label: context.translation.attachImage, files: _files), + 8.height, + ESignature( + title: context.translation.engSign, + oldSignature: _serviceReport.engSignature, + newSignature: _serviceReport.localEngSignature, + onSaved: (signature) { + // if (signature == null || signature.isEmpty) { + // setState(() {}); + // return; + // } + _serviceReport.localEngSignature = signature; + _serviceReport.engSignature = signature != null ? "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}" : null; + }, + ), + 24.height, + ], + ), + ).expanded, + AppFilledButton( + label: context.translation.updateRequest, + onPressed: () async { + if ((!_formKey.currentState.validate()) || (!(await _serviceReport.validate(context)))) { + setState(() {}); + return; + } + _formKey.currentState.save(); + _serviceReport.attachmentsWorkOrder ??= []; + if (_files.isEmpty) _serviceReport.attachmentsWorkOrder = []; + try { + for (var file in _files) { + _serviceReport.attachmentsWorkOrder.add(Attachment(id: 0, name: "${file.path.split("/").last}|${base64Encode(file.readAsBytesSync())}")); + } + } catch (error) { + print(error); + } + await _serviceRequestsProvider.updateServiceReport(context, report: _serviceReport); + }, ), - const ABackButton(), ], - ), + ).paddingAll(16), ), ), ), ); } - - bool _isLocalUrl(String url) { - if (url?.isEmpty != false) return false; - return url.startsWith("/") || url.startsWith("file://") || url.substring(1).startsWith(':\\'); - } } diff --git a/lib/views/pages/user/requests/work_order/future_service_report.dart b/lib/views/pages/user/requests/work_order/update_service_report.dart similarity index 53% rename from lib/views/pages/user/requests/work_order/future_service_report.dart rename to lib/views/pages/user/requests/work_order/update_service_report.dart index 937262b4..fb8bcee7 100644 --- a/lib/views/pages/user/requests/work_order/future_service_report.dart +++ b/lib/views/pages/user/requests/work_order/update_service_report.dart @@ -1,9 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:provider/provider.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/models/service_request/search_work_order.dart'; import 'package:test_sa/models/service_request/service_report.dart'; import 'package:test_sa/models/service_request/service_request.dart'; @@ -12,29 +8,23 @@ import 'package:test_sa/views/widgets/loaders/failed_loading.dart'; import 'edit_service_report.dart'; -class FutureServiceReport extends StatefulWidget { +class UpdateServiceReport extends StatefulWidget { final ServiceRequest request; final SearchWorkOrder workOrder; - const FutureServiceReport({Key key, this.request, this.workOrder}) : super(key: key); + const UpdateServiceReport({Key key, this.request, this.workOrder}) : super(key: key); @override - _FutureServiceReportState createState() => _FutureServiceReportState(); + _UpdateServiceReportState createState() => _UpdateServiceReportState(); } -class _FutureServiceReportState extends State { - UserProvider _userProvider; - SettingProvider _settingProvider; - +class _UpdateServiceReportState extends State { @override Widget build(BuildContext context) { - _userProvider = Provider.of(context); - _settingProvider = Provider.of(context); - - ServiceRequestsProvider().getSingleServiceReport(reportId: widget.workOrder.id, user: _userProvider.user, host: _settingProvider.host, subtitle: context.translation); + ServiceRequestsProvider().getSingleServiceReport(context, reportId: widget.workOrder.id); return Scaffold( body: FutureBuilder( - future: ServiceRequestsProvider().getSingleServiceReport(reportId: widget.workOrder.id, user: _userProvider.user, host: _settingProvider.host, subtitle: context.translation), + future: ServiceRequestsProvider().getSingleServiceReport(context, reportId: widget.workOrder.id), builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasError) { return FailedLoading( @@ -45,10 +35,7 @@ class _FutureServiceReportState extends State { ); } if (snapshot.connectionState == ConnectionState.done) { - return EditServiceReport( - report: snapshot.data, - request: widget.request, - ); + return EditServiceReport(report: snapshot.data, request: widget.request); } return const Center(child: ALoading()); }, diff --git a/lib/views/pages/user/requests/work_order/work_order_details_page.dart b/lib/views/pages/user/requests/work_order/work_order_details_page.dart index efc0c920..cd9d9ab1 100644 --- a/lib/views/pages/user/requests/work_order/work_order_details_page.dart +++ b/lib/views/pages/user/requests/work_order/work_order_details_page.dart @@ -14,7 +14,7 @@ import '../../../../../controllers/providers/api/user_provider.dart'; import '../../../../../models/enums/user_types.dart'; import '../../../../../models/service_request/search_work_order.dart'; import '../../../../widgets/requests/request_status.dart'; -import 'future_service_report.dart'; +import 'update_service_report.dart'; class WorkOrderDetailsPage extends StatelessWidget { static const String id = "/work_order_details_page"; @@ -79,7 +79,7 @@ class WorkOrderDetailsPage extends StatelessWidget { AppFilledButton( onPressed: () { Navigator.of(context).push( - MaterialPageRoute(builder: (_) => FutureServiceReport(request: serviceRequest, workOrder: workOrder)), + MaterialPageRoute(builder: (_) => UpdateServiceReport(request: serviceRequest, workOrder: workOrder)), ); }, label: context.translation.updateRequest, diff --git a/lib/views/pages/user/requests/work_order/work_orders_list_page.dart b/lib/views/pages/user/requests/work_order/work_orders_list_page.dart index 744e7a11..2f7ea3e6 100644 --- a/lib/views/pages/user/requests/work_order/work_orders_list_page.dart +++ b/lib/views/pages/user/requests/work_order/work_orders_list_page.dart @@ -14,7 +14,7 @@ import 'package:test_sa/new_views/app_style/app_color.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/pages/user/requests/work_order/create_service_report.dart'; -import 'package:test_sa/views/pages/user/requests/work_order/future_service_report.dart'; +import 'package:test_sa/views/pages/user/requests/work_order/update_service_report.dart'; import 'package:test_sa/views/pages/user/requests/work_order/work_order_details_page.dart'; import 'package:test_sa/views/widgets/requests/request_status.dart'; @@ -86,7 +86,7 @@ class WorkOrderListPage extends StatelessWidget { if (_userProvider.user.type == UsersTypes.engineer && serviceRequest.statusValue != 5 && serviceRequest.statusValue != 3) "edit".toSvgAsset(height: 48, width: 48).onPress(() { Navigator.of(context).push( - MaterialPageRoute(builder: (_) => FutureServiceReport(request: serviceRequest, workOrder: workOrders[index])), + MaterialPageRoute(builder: (_) => UpdateServiceReport(request: serviceRequest, workOrder: workOrders[index])), ); }) ], diff --git a/lib/views/widgets/e_signature/e_signature.dart b/lib/views/widgets/e_signature/e_signature.dart index 3ed11050..2fbf9e6a 100644 --- a/lib/views/widgets/e_signature/e_signature.dart +++ b/lib/views/widgets/e_signature/e_signature.dart @@ -6,6 +6,9 @@ import 'package:test_sa/extensions/text_extensions.dart'; import 'package:test_sa/extensions/widget_extensions.dart'; import 'package:test_sa/new_views/app_style/app_color.dart'; +import '../../app_style/sizing.dart'; +import '../loaders/image_loader.dart'; + class ESignature extends StatefulWidget { final String oldSignature; final Uint8List newSignature; @@ -35,7 +38,7 @@ class _ESignatureState extends State { if (widget.newSignature != null) { signature = widget.newSignature; } else if (widget.oldSignature != null || signature != null) { - signature = widget.oldSignature.codeUnits; + signature = Uint8List.fromList(widget.oldSignature.codeUnits); } super.initState(); } @@ -50,12 +53,13 @@ class _ESignatureState extends State { Widget build(BuildContext context) { return Column( children: [ - // if (widget.oldSignature != null || signature != null) - // Container( - // width: MediaQuery.of(context).size.width, - // padding: const EdgeInsets.only(bottom: 8), - // height: 90 * AppStyle.getScaleFactor(context), - // child: signature != null ? Image.memory(signature) : ImageLoader(boxFit: BoxFit.contain, url: widget.oldSignature)), + if (widget.oldSignature != null || signature != null) + Container( + width: MediaQuery.of(context).size.width, + padding: const EdgeInsets.only(bottom: 8), + height: 90 * AppStyle.getScaleFactor(context), + child: signature != null ? Image.memory(signature) : ImageLoader(boxFit: BoxFit.contain, url: widget.oldSignature), + ), FormField(onSaved: (_) async { widget.onSaved(signature); }, builder: (FormFieldState state) {