diff --git a/lib/constants/app_constants.dart b/lib/constants/app_constants.dart index b1b4aa37cd83439436daae98497247a93fa6bbb6..110954688c898be9fe023304cbe2aac1a55711a6 100644 --- a/lib/constants/app_constants.dart +++ b/lib/constants/app_constants.dart @@ -21,6 +21,7 @@ class InspectionStatus { static const String newInspection = 'NEW'; static const String sentForInspection = 'SENTFORINS'; static const String inspectionCompleted = 'INSCOMPLETED'; + static const String leadInspectorCompleted = 'LEADINSCOMPLETED'; static const String inspectionPending = 'PENDING'; static const String returned = 'RETURNED'; } diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 7abaf4367e204a8c9e2303bbca21304e5b83092a..acbfc9825bd2a436712cef13fb53e4015facc7b6 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -15,6 +15,7 @@ "next": "Next", "previous": "previous", "inspectionCompleted": "Inspection completed", + "leadInspectorCompleted": "Lead inspector completed", "completed": "Completed", "sentForInspection": "Sent for inspection", "noApplications": "No applications at the moment", diff --git a/lib/models/application_model.dart b/lib/models/application_model.dart index 54c47432f50770184d39704f2bacba52c6b17bbd..f1ecb95c224df384c87db03677b6aee689b14640 100644 --- a/lib/models/application_model.dart +++ b/lib/models/application_model.dart @@ -11,6 +11,7 @@ class Application { final List leadInspector; final Map inspectorDataObject; final Map inspectorSummaryDataObject; + final String inspectionStatus; final String scheduledDate; final String createdDate; final String createdBy; @@ -26,6 +27,7 @@ class Application { required this.leadInspector, required this.inspectorDataObject, required this.inspectorSummaryDataObject, + required this.inspectionStatus, required this.scheduledDate, required this.createdDate, required this.createdBy, @@ -45,6 +47,7 @@ class Application { ? json['inspectorDataObject']['dataObject'] : {}, inspectorSummaryDataObject: json['inspectorSummaryDataObject'] ?? {}, + inspectionStatus: json['inspection']['status'] ?? '', scheduledDate: json['inspection']['scheduledDate'] ?? '', createdDate: json['createdDate'], createdBy: json['createdBy'], @@ -62,6 +65,7 @@ class Application { leadInspector, inspectorDataObject, inspectorSummaryDataObject, + inspectionStatus, scheduledDate, createdDate, createdBy diff --git a/lib/pages/application_details_page.dart b/lib/pages/application_details_page.dart index d0a8659a4f2b6a995b736b05c68d8c4e7a0b5455..d11576323bd04aa875a5a4d4df2d450b34c1e356 100644 --- a/lib/pages/application_details_page.dart +++ b/lib/pages/application_details_page.dart @@ -50,6 +50,7 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> final List<Map> _inspectors = []; String _inspectionSummary = ''; String _errorMessage = ''; + String _inspectionStatus = ''; @override void initState() { @@ -87,6 +88,18 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> 'name': '${widget.application.inspectors[i]['firstName']} ${widget.application.inspectors[i]['lastName']}', }); + if (widget.application.inspectors[i]['id'] == userId && + !_isleadInspector) { + _note = widget.application.inspectors[i]['comments'] ?? ''; + _inspectionStatus = widget.application.inspectors[i]['status'] ?? false; + _iConcent = + widget.application.inspectors[i]['consentApplication'] ?? false; + if (widget.application.inspectors[i]['consentApplication'] != null) { + _iDisagree = widget.application.inspectors[i]['consentApplication'] + ? false + : true; + } + } setState(() {}); } } @@ -234,6 +247,7 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> builder: (context) => StatefulBuilder(builder: (context, setState) { return AssistantInspectorDialog( noteText: _note, + status: _inspectionStatus, parentAction: triggerUpdate, ); })); @@ -247,7 +261,7 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> @override Widget build(BuildContext context) { - // print(widget.applicationFields); + // print(widget.application.inspectorDataObject); return Scaffold( key: _scaffoldKey, appBar: AppBar( @@ -633,7 +647,14 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> field.keys .elementAt(i)], applicationStatus: widget - .application.status, + .application + .inspectionStatus == + InspectionStatus + .leadInspectorCompleted + ? InspectionStatus + .inspectionCompleted + : widget + .application.status, parentAction: updateField, ) : widget.application.status == @@ -691,12 +712,19 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> ? ButtonTheme( child: OutlinedButton( onPressed: () { - if (!_iDisagree) { + if (!_iDisagree && + _inspectionStatus != + InspectionStatus + .inspectionCompleted) { _displayCommentDialog(); } - setState(() { - _iDisagree = !_iDisagree; - }); + if (_inspectionStatus != + InspectionStatus + .inspectionCompleted) { + setState(() { + _iDisagree = !_iDisagree; + }); + } }, style: OutlinedButton.styleFrom( backgroundColor: _iDisagree @@ -743,12 +771,19 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> padding: const EdgeInsets.only(left: 10), child: TextButton( onPressed: () { - if (!_iConcent) { + if (!_iConcent && + _inspectionStatus != + InspectionStatus + .inspectionCompleted) { _displayCommentDialog(); } - setState(() { - _iConcent = !_iConcent; - }); + if (_inspectionStatus != + InspectionStatus + .inspectionCompleted) { + setState(() { + _iConcent = !_iConcent; + }); + } }, style: TextButton.styleFrom( // primary: Colors.white, @@ -863,7 +898,9 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> ], )) : widget.application.status != - InspectionStatus.inspectionCompleted + InspectionStatus.inspectionCompleted && + widget.application.inspectionStatus != + InspectionStatus.leadInspectorCompleted ? TextButton( onPressed: () { _submitInspection(); diff --git a/lib/repositories/application_repository.dart b/lib/repositories/application_repository.dart index a970840830c8fdf727b660a8f680329b470af924..90b4687dbaea56a7faa173cfd3f0e3f151ad1184 100644 --- a/lib/repositories/application_repository.dart +++ b/lib/repositories/application_repository.dart @@ -6,6 +6,7 @@ import 'package:smf_mobile/database/offline_model.dart'; import 'package:smf_mobile/models/application_model.dart'; import 'package:smf_mobile/services/application_service.dart'; import 'package:smf_mobile/util/helper.dart'; +import 'dart:developer' as developer; class ApplicationRespository with ChangeNotifier { late Map _data; diff --git a/lib/util/helper.dart b/lib/util/helper.dart index 3b6cb3ff30ffd9df33b0ec733b08306fd9a652b2..ecebd84db69670c5f9019f45bcda4642f762cd83 100644 --- a/lib/util/helper.dart +++ b/lib/util/helper.dart @@ -76,12 +76,19 @@ class Helper { static getInspectionStatus(BuildContext context, String status) { String _inspectionStatus = ''; - if (status == InspectionStatus.inspectionCompleted) { - _inspectionStatus = AppLocalizations.of(context)!.completed; - } else if (status == InspectionStatus.sentForInspection) { - _inspectionStatus = AppLocalizations.of(context)!.sentForInspection; - } else { - _inspectionStatus = capitalize(status); + switch (status) { + case InspectionStatus.inspectionCompleted: + _inspectionStatus = AppLocalizations.of(context)!.completed; + break; + case InspectionStatus.sentForInspection: + _inspectionStatus = AppLocalizations.of(context)!.sentForInspection; + break; + case InspectionStatus.leadInspectorCompleted: + _inspectionStatus = + AppLocalizations.of(context)!.leadInspectorCompleted; + break; + default: + _inspectionStatus = capitalize(status); } // print(_inspectionStatus); return _inspectionStatus; diff --git a/lib/widgets/application_card.dart b/lib/widgets/application_card.dart index 5e8b2d5c8b70a76ed21537a4105c1842c8708ec5..26534f72f8b5a99f639c976e574270df2c585608 100644 --- a/lib/widgets/application_card.dart +++ b/lib/widgets/application_card.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:smf_mobile/constants/app_constants.dart'; import 'package:smf_mobile/constants/app_urls.dart'; import 'package:smf_mobile/constants/color_constants.dart'; import 'package:smf_mobile/models/application_model.dart'; @@ -23,6 +24,19 @@ class _ApplicationCardState extends State<ApplicationCard> { super.initState(); } + String _getApplicationStatus(String inspetionStatus, String actualStatus) { + String status = ''; + if (actualStatus == InspectionStatus.inspectionCompleted) { + status = InspectionStatus.inspectionCompleted; + } + if (inspetionStatus == InspectionStatus.leadInspectorCompleted) { + status = InspectionStatus.leadInspectorCompleted; + } else { + status = actualStatus; + } + return status; + } + @override Widget build(BuildContext context) { return InkWell( @@ -96,7 +110,10 @@ class _ApplicationCardState extends State<ApplicationCard> { padding: const EdgeInsets.only(bottom: 10), child: Text( Helper.getInspectionStatus( - context, widget.application.status), + context, + _getApplicationStatus( + widget.application.inspectionStatus, + widget.application.status)), style: GoogleFonts.lato( color: AppColors.black60, fontSize: 14.0, diff --git a/lib/widgets/assistant_inspector_dialog.dart b/lib/widgets/assistant_inspector_dialog.dart index b279de80490101bd8977b63f7072597d1ab309ae..b927e4a35501e60a8dfa18200d981f0875a04526 100644 --- a/lib/widgets/assistant_inspector_dialog.dart +++ b/lib/widgets/assistant_inspector_dialog.dart @@ -1,15 +1,18 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:smf_mobile/constants/app_constants.dart'; import 'package:smf_mobile/constants/color_constants.dart'; // import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class AssistantInspectorDialog extends StatefulWidget { final String noteText; + final String status; final ValueChanged<Map> parentAction; const AssistantInspectorDialog({ Key? key, required this.noteText, + required this.status, required this.parentAction, }) : super(key: key); @@ -83,6 +86,10 @@ class _AssistantInspectorDialogState extends State<AssistantInspectorDialog> { child: Focus( child: TextFormField( // autofocus: true, + enabled: widget.status == + InspectionStatus.inspectionCompleted + ? false + : true, controller: _noteController, textCapitalization: TextCapitalization.sentences, @@ -121,7 +128,10 @@ class _AssistantInspectorDialogState extends State<AssistantInspectorDialog> { child: OutlinedButton( onPressed: () { Navigator.of(context).pop(false); - _saveData(false); + if (widget.status != + InspectionStatus.inspectionCompleted) { + _saveData(false); + } }, style: OutlinedButton.styleFrom( // primary: Colors.white, @@ -146,7 +156,10 @@ class _AssistantInspectorDialogState extends State<AssistantInspectorDialog> { child: OutlinedButton( onPressed: () { Navigator.of(context).pop(false); - _saveData(true); + if (widget.status != + InspectionStatus.inspectionCompleted) { + _saveData(true); + } }, style: OutlinedButton.styleFrom( // primary: Colors.white, @@ -171,7 +184,10 @@ class _AssistantInspectorDialogState extends State<AssistantInspectorDialog> { child: TextButton( onPressed: () { Navigator.of(context).pop(false); - _saveData(true); + if (widget.status != + InspectionStatus.inspectionCompleted) { + _saveData(true); + } }, style: TextButton.styleFrom( // primary: Colors.white,