diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 4bc5dad8fa0eeb7448d86a70d13b982812251583..102ddc8f29c8af76ed0350896738fd578053a569 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -9,6 +9,7 @@ "pinAlreadyExists": "Pin already exists, please choose different one", "createPin": "Create PIN", "inValidPin": "Invalid PIN", + "inValidEmailId": "Invalid Email Id", "getOtp": "GET OTP", "enterOtp": "Enter OTP", "otpFieldDescription": "Enter the 6 digit OTP sent to your email address.", @@ -51,6 +52,7 @@ "iConsent": "I consent", "acceptTermsAndConditions": "Please accept terms and conditions", "dataSynchoronized": "Data synchoronized", - "dataSynchoronizedText": "Data has been synchoronized" + "dataSynchoronizedText": "Data has been synchoronized", + "formNotAvailable": "Form not available" } \ No newline at end of file diff --git a/lib/pages/application_details_page.dart b/lib/pages/application_details_page.dart index 124c5cc9abdcf7c5ea742d34c72ec90af1e6b99a..9cc244167ab4d2c396edf0441e2514edb4a26829 100644 --- a/lib/pages/application_details_page.dart +++ b/lib/pages/application_details_page.dart @@ -167,7 +167,6 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> _data.forEach((key, value) => _fields.add(value)); } else { Map existingData = {}; - print(_leadInspectorId); widget.application.dataObject.forEach((key, value) => { updatedFields = {}, existingData = widget.application.inspectorDataObject[key], @@ -183,6 +182,11 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> ? existingData[childKey] [existingData[childKey].keys.elementAt(0)] ['comments'] + : '', + 'inspectionValue': _isleadInspector + ? existingData[childKey] + [existingData[childKey].keys.elementAt(0)] + ['inspectionValue'] : '' } } diff --git a/lib/pages/create_pin_page.dart b/lib/pages/create_pin_page.dart index e3eda0e9dfd2eb17ba58e1f852965aa7200910a5..87284176a2885cbb27b97c8e82f66af312ee22ff 100644 --- a/lib/pages/create_pin_page.dart +++ b/lib/pages/create_pin_page.dart @@ -1,3 +1,4 @@ +import 'package:email_validator/email_validator.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; @@ -106,6 +107,16 @@ class _CreatePinPageState extends State<CreatePinPage> { } } + _validateEmail() { + String email = _emailController.text; + final bool isValid = EmailValidator.validate(email); + SystemChannels.textInput.invokeMethod('TextInput.hide'); + if (!isValid) { + _emailController.text = ''; + Helper.toastMessage(AppLocalizations.of(context)!.inValidEmailId); + } + } + @override void dispose() { super.dispose(); @@ -201,6 +212,8 @@ class _CreatePinPageState extends State<CreatePinPage> { ), child: Focus( child: TextFormField( + onEditingComplete: () => + _validateEmail(), textCapitalization: TextCapitalization.none, textInputAction: TextInputAction.done, @@ -271,10 +284,10 @@ class _CreatePinPageState extends State<CreatePinPage> { child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - OtpInputField(_pinOneFieldOne, true), - OtpInputField(_pinOneFieldTwo, false), - OtpInputField(_pinOneFieldThree, false), - OtpInputField(_pinOneFieldFour, false) + OtpInputField(_pinOneFieldOne, true, false), + OtpInputField(_pinOneFieldTwo, false, false), + OtpInputField(_pinOneFieldThree, false, false), + OtpInputField(_pinOneFieldFour, false, true) ], ), ), @@ -306,10 +319,10 @@ class _CreatePinPageState extends State<CreatePinPage> { child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - OtpInputField(_pinTwoFieldOne, true), - OtpInputField(_pinTwoFieldTwo, false), - OtpInputField(_pinTwoFieldThree, false), - OtpInputField(_pinTwoFieldFour, false) + OtpInputField(_pinTwoFieldOne, true, false), + OtpInputField(_pinTwoFieldTwo, false, false), + OtpInputField(_pinTwoFieldThree, false, false), + OtpInputField(_pinTwoFieldFour, false, true) ], ), ), diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index 335369aa377d03b11a06b4ba36a90db5714e9f58..971ee17e7073f3d4fd6a026a4d4d6a1eef3d7d72 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -126,6 +126,8 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver { } Future<dynamic> _getApplications() async { + String rawUserId = await Helper.getUser(Storage.userId); + int userId = int.parse(rawUserId); bool isInternetConnected = await Helper.isInternetConnected(); // await Future.delayed(const Duration(milliseconds: 10)); if (isInternetConnected) { @@ -152,7 +154,13 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver { DateTime.now(), DateTime.parse(temp.join("-"))); if ((days == 0 || days > 0) && application.status == InspectionStatus.sentForInspection) { - _pendingApplications.add(application); + if (application.leadInspector[0] == userId && + application.inspectionStatus == + InspectionStatus.leadInspectorCompleted) { + _pastApplications.add(application); + } else { + _pendingApplications.add(application); + } } else if ((days == 0 || days > 0) && application.status != InspectionStatus.sentForInspection) { _pastApplications.add(application); diff --git a/lib/pages/login_email_page.dart b/lib/pages/login_email_page.dart index 7d5532428fff54281ab63f06533e2f3b1bde1d06..d7691547c80a3c48fe8fd66f0cb525821c3e5378 100644 --- a/lib/pages/login_email_page.dart +++ b/lib/pages/login_email_page.dart @@ -15,6 +15,8 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:smf_mobile/widgets/otp_input_field.dart'; import 'package:unique_identifier/unique_identifier.dart'; import 'dart:async'; +import 'package:email_validator/email_validator.dart'; + // import 'package:connectivity_plus/connectivity_plus.dart'; // import 'package:smf_mobile/util/connectivity_helper.dart'; @@ -40,6 +42,7 @@ class _LoginEmailPageState extends State<LoginEmailPage> { final TextEditingController _fieldTwo = TextEditingController(); final TextEditingController _fieldThree = TextEditingController(); final TextEditingController _fieldFour = TextEditingController(); + String _oldPin = ''; @override @@ -134,6 +137,10 @@ class _LoginEmailPageState extends State<LoginEmailPage> { builder: (context) => const HomePage(), )); } else { + _fieldOne.text = ''; + _fieldTwo.text = ''; + _fieldThree.text = ''; + _fieldFour.text = ''; Helper.toastMessage(AppLocalizations.of(context)!.inValidPin); } } catch (err) { @@ -142,6 +149,16 @@ class _LoginEmailPageState extends State<LoginEmailPage> { } } + _validateEmail() { + String email = _emailController.text; + final bool isValid = EmailValidator.validate(email); + SystemChannels.textInput.invokeMethod('TextInput.hide'); + if (!isValid) { + _emailController.text = ''; + Helper.toastMessage(AppLocalizations.of(context)!.inValidEmailId); + } + } + @override void dispose() { // _connectivity.disposeStream(); @@ -238,6 +255,8 @@ class _LoginEmailPageState extends State<LoginEmailPage> { ), child: Focus( child: TextFormField( + onEditingComplete: () => + _validateEmail(), textCapitalization: TextCapitalization.none, textInputAction: TextInputAction.done, @@ -349,10 +368,10 @@ class _LoginEmailPageState extends State<LoginEmailPage> { child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - OtpInputField(_fieldOne, true), - OtpInputField(_fieldTwo, false), - OtpInputField(_fieldThree, false), - OtpInputField(_fieldFour, false) + OtpInputField(_fieldOne, true, false), + OtpInputField(_fieldTwo, false, false), + OtpInputField(_fieldThree, false, false), + OtpInputField(_fieldFour, false, true) ], ), ), diff --git a/lib/pages/login_otp_page.dart b/lib/pages/login_otp_page.dart index 3237596e09737ff1c4a009b5254ebdbd278cb93f..0f633f8fe7d4c333169ffb67526d670f6dbcb707 100644 --- a/lib/pages/login_otp_page.dart +++ b/lib/pages/login_otp_page.dart @@ -235,12 +235,13 @@ class _LoginOtpPageState extends State<LoginOtpPage> { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - OtpInputField(_fieldOne, true), - OtpInputField(_fieldTwo, false), - OtpInputField(_fieldThree, false), - OtpInputField(_fieldFour, false), - OtpInputField(_fieldFive, false), - OtpInputField(_fieldSix, false) + OtpInputField(_fieldOne, true, false), + OtpInputField(_fieldTwo, false, false), + OtpInputField( + _fieldThree, false, false), + OtpInputField(_fieldFour, false, false), + OtpInputField(_fieldFive, false, false), + OtpInputField(_fieldSix, false, true) ], ), ), diff --git a/lib/repositories/form_repository.dart b/lib/repositories/form_repository.dart index c95464435355b1825968d744b8905698c9e0c22f..6727d3e33e0035cdcde8b00a3141c87c8506b88f 100644 --- a/lib/repositories/form_repository.dart +++ b/lib/repositories/form_repository.dart @@ -61,11 +61,17 @@ class FormRespository with ChangeNotifier { var rawData = await OfflineModel.getForms(username); Map formData = json.decode(rawData['form_data']); List forms = formData['responseData']; + // print('formId: $formId'); for (var form in forms) { + // print(form['id']); if (form['id'] == formId) { + // print(form.toString()); formDetails = form; } } + if (formDetails['id'] == null) { + Helper.toastMessage('Form not available'); + } } catch (_) { return _; } diff --git a/lib/widgets/lead_inspector_application_field.dart b/lib/widgets/lead_inspector_application_field.dart index d6f70404e52fcda591d167b48a357013a53e555e..7e73ae7880f61d87d7c18e653dacea5d9e5bfda8 100644 --- a/lib/widgets/lead_inspector_application_field.dart +++ b/lib/widgets/lead_inspector_application_field.dart @@ -50,15 +50,45 @@ class _LeadInspectorApplicationFieldState } triggerUpdate(Map dialogData) { - Map data = { - widget.fieldName: { - widget.fieldData.keys.elementAt(0): { - 'value': _radioValue, - 'comments': dialogData['summaryText'], - 'inspectionValue': dialogData['inspectionValue'] - } + Map data = {}; + if (dialogData['cancelStatus'] != null) { + if (dialogData['cancelStatus'] && + (dialogData['summaryText'] == '' || + dialogData['inspectionValue'] == '')) { + setState(() { + _radioValue = FieldValue.correct; + }); + data = { + widget.fieldName: { + widget.fieldData.keys.elementAt(0): { + 'value': FieldValue.correct, + 'comments': '', + 'inspectionValue': '' + } + } + }; + } else { + data = { + widget.fieldName: { + widget.fieldData.keys.elementAt(0): { + 'value': _radioValue, + 'comments': dialogData['summaryText'], + 'inspectionValue': dialogData['inspectionValue'] + } + } + }; } - }; + } else { + data = { + widget.fieldName: { + widget.fieldData.keys.elementAt(0): { + 'value': _radioValue, + 'comments': dialogData['summaryText'], + 'inspectionValue': dialogData['inspectionValue'] + } + } + }; + } // print(data); setState(() { _summaryText = dialogData['summaryText']; @@ -69,6 +99,7 @@ class _LeadInspectorApplicationFieldState Future _displayCommentDialog() { return showDialog( + barrierDismissible: false, context: context, builder: (context) => StatefulBuilder(builder: (context, setState) { return LeadInspectorDialog( diff --git a/lib/widgets/lead_inspector_dialog.dart b/lib/widgets/lead_inspector_dialog.dart index 8e788cd248b3a86d9e4b39089877ddc9f2ea4bdf..0bec891adf4d7e77e7f725a7a33a609d4469fb4c 100644 --- a/lib/widgets/lead_inspector_dialog.dart +++ b/lib/widgets/lead_inspector_dialog.dart @@ -3,6 +3,7 @@ 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:smf_mobile/util/helper.dart'; import 'package:smf_mobile/widgets/questions/dropdown_question.dart'; import 'package:smf_mobile/widgets/questions/multi_select_question.dart'; import 'package:smf_mobile/widgets/questions/radio_question.dart'; @@ -42,6 +43,14 @@ class _LeadInspectorDialogState extends State<LeadInspectorDialog> { } saveData(String inspectionValue) { + // if (_summaryController.text == '') { + // Helper.toastMessage('Please enter reason'); + // return; + // } + // if (inspectionValue == '') { + // Helper.toastMessage('Please enter actual value'); + // return; + // } setState(() { _inspectionValue = inspectionValue; }); @@ -52,8 +61,20 @@ class _LeadInspectorDialogState extends State<LeadInspectorDialog> { widget.parentAction(data); } - _submitData() { + _submitData(bool cancel) { + if (!cancel) { + if (_summaryController.text == '') { + Helper.toastMessage('Please enter reason'); + return; + } + if (_inspectionValue == '') { + Helper.toastMessage('Please enter actual value'); + return; + } + } + Navigator.of(context).pop(false); data = { + 'cancelStatus': cancel, 'summaryText': _summaryController.text, 'inspectionValue': _inspectionValue }; @@ -192,8 +213,7 @@ class _LeadInspectorDialogState extends State<LeadInspectorDialog> { ButtonTheme( child: OutlinedButton( onPressed: () { - Navigator.of(context).pop(false); - _submitData(); + _submitData(true); }, style: OutlinedButton.styleFrom( // primary: Colors.white, @@ -217,8 +237,7 @@ class _LeadInspectorDialogState extends State<LeadInspectorDialog> { padding: const EdgeInsets.only(left: 10), child: TextButton( onPressed: () { - Navigator.of(context).pop(false); - _submitData(); + _submitData(false); }, style: TextButton.styleFrom( // primary: Colors.white, diff --git a/lib/widgets/otp_input_field.dart b/lib/widgets/otp_input_field.dart index 8bf0c157d18a1006e4cc8172487c857bd21a025a..dffe3113b34deb57a254de97d9897157ab524596 100644 --- a/lib/widgets/otp_input_field.dart +++ b/lib/widgets/otp_input_field.dart @@ -1,11 +1,13 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:smf_mobile/constants/color_constants.dart'; class OtpInputField extends StatefulWidget { final TextEditingController controller; final bool autoFocus; - const OtpInputField(this.controller, this.autoFocus, {Key? key}) + final bool isLast; + const OtpInputField(this.controller, this.autoFocus, this.isLast, {Key? key}) : super(key: key); @override _OtpInputFieldState createState() => _OtpInputFieldState(); @@ -15,33 +17,50 @@ class _OtpInputFieldState extends State<OtpInputField> { @override Widget build(BuildContext context) { return SizedBox( - height: 40, - width: 40, - child: TextField( - // autofocus: widget.autoFocus, - textAlign: TextAlign.center, - keyboardType: TextInputType.number, - controller: widget.controller, - maxLength: 1, - cursorColor: AppColors.black08, - style: GoogleFonts.lato( - color: AppColors.black40, - fontSize: 16, - letterSpacing: - 0 /*percentages not used in flutter. defaulting to zero*/, - fontWeight: FontWeight.normal, - height: 1 /*PERCENT not supported*/ - ), - decoration: const InputDecoration( - border: OutlineInputBorder(), - counterText: '', - hintStyle: TextStyle(color: AppColors.black40, fontSize: 20.0)), - onChanged: (value) { - if (value.length == 1) { - FocusScope.of(context).nextFocus(); - } - }, - ), - ); + height: 40, + width: 40, + child: RawKeyboardListener( + focusNode: FocusNode(), + onKey: (event) { + if (event.logicalKey == LogicalKeyboardKey.backspace && + widget.controller.text == '' && + !widget.autoFocus) { + if (widget.isLast && widget.controller.text == '') { + FocusScope.of(context).previousFocus(); + } else if (!widget.isLast) { + FocusScope.of(context).previousFocus(); + } + } + }, + child: TextField( + // autofocus: widget.autoFocus, + textAlign: TextAlign.center, + keyboardType: TextInputType.number, + controller: widget.controller, + maxLength: 1, + cursorColor: AppColors.black08, + style: GoogleFonts.lato( + color: AppColors.black40, + fontSize: 16, + letterSpacing: + 0 /*percentages not used in flutter. defaulting to zero*/, + fontWeight: FontWeight.normal, + height: 1 /*PERCENT not supported*/ + ), + decoration: const InputDecoration( + border: OutlineInputBorder(), + counterText: '', + hintStyle: TextStyle(color: AppColors.black40, fontSize: 20.0)), + onChanged: (value) { + if (value.length == 1) { + if (!widget.isLast) { + FocusScope.of(context).nextFocus(); + } else { + SystemChannels.textInput.invokeMethod('TextInput.hide'); + } + } + }, + ), + )); } } diff --git a/lib/widgets/questions/dropdown_question.dart b/lib/widgets/questions/dropdown_question.dart index 9044e26fc66c3dc0dba7971ae5325b2e721d877c..05ea3b8a242ab4680a84d3551a353dc731050fe1 100644 --- a/lib/widgets/questions/dropdown_question.dart +++ b/lib/widgets/questions/dropdown_question.dart @@ -28,6 +28,7 @@ class _DropdownQuestionState extends State<DropdownQuestion> { } void initializeDropdown() { + _dropdownItems.add('Please select any option'); for (var item in widget.items) { _dropdownItems.add(item['value']); } @@ -75,9 +76,12 @@ class _DropdownQuestionState extends State<DropdownQuestion> { }).toList(); }, onChanged: (newValue) { + String optionSelected = newValue.toString(); setState(() { - _dropdownValue = newValue.toString(); - widget.parentAction(newValue.toString()); + _dropdownValue = optionSelected; + widget.parentAction(optionSelected == 'Please select any option' + ? '' + : optionSelected); }); }, items: _dropdownItems.map<DropdownMenuItem<String>>((String value) { diff --git a/lib/widgets/questions/text_question.dart b/lib/widgets/questions/text_question.dart index 6a7ccb7e52fe214427165f10d84dd819839dba80..4cc30086a5acbee241f56832d80c2d1f3c1bad04 100644 --- a/lib/widgets/questions/text_question.dart +++ b/lib/widgets/questions/text_question.dart @@ -46,7 +46,7 @@ class _TextQuestionState extends State<TextQuestion> { child: Focus( child: TextFormField( onEditingComplete: () { - // widget.parentAction(_textController.text.toString()); + widget.parentAction(_textController.text.toString()); SystemChannels.textInput.invokeMethod('TextInput.hide'); // return; }, diff --git a/pubspec.lock b/pubspec.lock index 0de1cc52d77e7e4750b37dc6f65533e0d30b6139..16fd0f5cf060966515d8fbf24935ea691783fb7a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -134,6 +134,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.7.1" + email_validator: + dependency: "direct main" + description: + name: email_validator + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" fake_async: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 28443e29e6cf0edfeef25c5fdde67039b79ae7d1..cbe066e9d1b6e3f6b7d42315c207279ae3a662cf 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -51,6 +51,7 @@ dependencies: sqflite: ^2.0.2 connectivity_plus: ^2.2.1 change_app_package_name: ^1.0.0 + email_validator: ^2.0.1 dev_dependencies: flutter_test: