From 1dca3076d927615cba8ad51c6b7c6ed5db93ce0f Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Tue, 4 Apr 2023 15:51:08 +0300 Subject: [PATCH 1/3] Survey dynamic questions --- lib/app_state/app_state.dart | 2 +- lib/models/itg/itg_response_model.dart | 5 +- lib/models/itg/survey_model.dart | 148 +++++++++ lib/ui/landing/dashboard_screen.dart | 15 +- lib/ui/landing/itg/survey_screen.dart | 310 +++++++++++++----- lib/ui/work_list/item_history_screen.dart | 13 +- .../worklist_fragments/actions_fragment.dart | 15 +- lib/widgets/mark_attendance_widget.dart | 27 +- 8 files changed, 444 insertions(+), 91 deletions(-) create mode 100644 lib/models/itg/survey_model.dart diff --git a/lib/app_state/app_state.dart b/lib/app_state/app_state.dart index 293afbb..7ccdd4f 100644 --- a/lib/app_state/app_state.dart +++ b/lib/app_state/app_state.dart @@ -90,7 +90,7 @@ class AppState { String get getHuaweiPushToken => _huaweiPushToken; - final PostParamsModel _postParamsInitConfig = PostParamsModel(channel: 31, versionID: 4.5, mobileType: Platform.isAndroid ? "android" : "ios"); + final PostParamsModel _postParamsInitConfig = PostParamsModel(channel: 31, versionID: 4.8, mobileType: Platform.isAndroid ? "android" : "ios"); void setPostParamsInitConfig() { isAuthenticated = false; diff --git a/lib/models/itg/itg_response_model.dart b/lib/models/itg/itg_response_model.dart index 4dff106..dff7869 100644 --- a/lib/models/itg/itg_response_model.dart +++ b/lib/models/itg/itg_response_model.dart @@ -5,6 +5,7 @@ import 'dart:convert'; import 'package:mohem_flutter_app/models/itg/advertisement.dart'; +import 'package:mohem_flutter_app/models/itg/survey_model.dart'; MohemmItgResponseItem mohemmItgResponseItemFromJson(String str) => MohemmItgResponseItem.fromJson(json.decode(str)); @@ -103,7 +104,7 @@ class ItgResponseData { final bool? isDeleted; final bool? showDelete; final Advertisement? advertisement; - final dynamic survey; + final SurveyModel? survey; final dynamic isActive; final dynamic pageSize; final dynamic pageNo; @@ -126,7 +127,7 @@ class ItgResponseData { isDeleted: json["isDeleted"] == null ? null : json["isDeleted"], showDelete: json["showDelete"] == null ? null : json["showDelete"], advertisement: json["advertisement"] == null ? null : Advertisement.fromJson(json["advertisement"]), - survey: json["survey"], + survey: json["survey"] == null ? null : SurveyModel.fromJson(json["survey"]), isActive: json["isActive"], pageSize: json["pageSize"], pageNo: json["pageNo"], diff --git a/lib/models/itg/survey_model.dart b/lib/models/itg/survey_model.dart new file mode 100644 index 0000000..7cdbbdd --- /dev/null +++ b/lib/models/itg/survey_model.dart @@ -0,0 +1,148 @@ +class SurveyModel { + int? surveyId; + String? referenceNo; + String? title; + String? description; + List? questions; + bool? isActive; + Null? pageSize; + Null? pageNo; + Null? languageId; + + SurveyModel({this.surveyId, this.referenceNo, this.title, this.description, this.questions, this.isActive, this.pageSize, this.pageNo, this.languageId}); + + SurveyModel.fromJson(Map json) { + surveyId = json['surveyId']; + referenceNo = json['referenceNo']; + title = json['title']; + description = json['description']; + if (json['questions'] != null) { + questions = []; + json['questions'].forEach((v) { + questions!.add(new Questions.fromJson(v)); + }); + } + isActive = json['isActive']; + pageSize = json['pageSize']; + pageNo = json['pageNo']; + languageId = json['languageId']; + } + + Map toJson() { + Map data = new Map(); + data['surveyId'] = this.surveyId; + data['referenceNo'] = this.referenceNo; + data['title'] = this.title; + data['description'] = this.description; + if (this.questions != null) { + data['questions'] = this.questions!.map((v) => v.toJson()).toList(); + } + data['isActive'] = this.isActive; + data['pageSize'] = this.pageSize; + data['pageNo'] = this.pageNo; + data['languageId'] = this.languageId; + return data; + } +} + +class Questions { + int? questionId; + String? title; + bool? isRequired; + String? type; + int? sequenceNo; + Null? surveyId; + List? options; + Null? rspPercentage; + Null? isActive; + Null? pageSize; + Null? pageNo; + Null? languageId; + + Questions({this.questionId, this.title, this.isRequired, this.type, this.sequenceNo, this.surveyId, this.options, this.rspPercentage, this.isActive, this.pageSize, this.pageNo, this.languageId}); + + Questions.fromJson(Map json) { + questionId = json['questionId']; + title = json['title']; + isRequired = json['isRequired']; + type = json['type']; + sequenceNo = json['sequenceNo']; + surveyId = json['surveyId']; + if (json['options'] != null) { + options = []; + json['options'].forEach((v) { + options!.add(new Options.fromJson(v)); + }); + } + rspPercentage = json['rspPercentage']; + isActive = json['isActive']; + pageSize = json['pageSize']; + pageNo = json['pageNo']; + languageId = json['languageId']; + } + + Map toJson() { + Map data = new Map(); + data['questionId'] = this.questionId; + data['title'] = this.title; + data['isRequired'] = this.isRequired; + data['type'] = this.type; + data['sequenceNo'] = this.sequenceNo; + data['surveyId'] = this.surveyId; + if (this.options != null) { + data['options'] = this.options!.map((v) => v.toJson()).toList(); + } + data['rspPercentage'] = this.rspPercentage; + data['isActive'] = this.isActive; + data['pageSize'] = this.pageSize; + data['pageNo'] = this.pageNo; + data['languageId'] = this.languageId; + return data; + } +} + +class Options { + int? optionId; + String? title; + bool? isCommentsRequired; + int? sequenceNo; + int? questionId; + Null? rspPercentage; + Null? count; + Null? isActive; + Null? pageSize; + Null? pageNo; + Null? languageId; + + Options({this.optionId, this.title, this.isCommentsRequired, this.sequenceNo, this.questionId, this.rspPercentage, this.count, this.isActive, this.pageSize, this.pageNo, this.languageId}); + + Options.fromJson(Map json) { + optionId = json['optionId']; + title = json['title']; + isCommentsRequired = json['isCommentsRequired']; + sequenceNo = json['sequenceNo']; + questionId = json['questionId']; + rspPercentage = json['rspPercentage']; + count = json['count']; + isActive = json['isActive']; + pageSize = json['pageSize']; + pageNo = json['pageNo']; + languageId = json['languageId']; + } + + Map toJson() { + Map data = new Map(); + data['optionId'] = this.optionId; + data['title'] = this.title; + data['isCommentsRequired'] = this.isCommentsRequired; + data['sequenceNo'] = this.sequenceNo; + data['questionId'] = this.questionId; + data['rspPercentage'] = this.rspPercentage; + data['count'] = this.count; + data['isActive'] = this.isActive; + data['pageSize'] = this.pageSize; + data['pageNo'] = this.pageNo; + data['languageId'] = this.languageId; + return data; + } +} diff --git a/lib/ui/landing/dashboard_screen.dart b/lib/ui/landing/dashboard_screen.dart index 58fc76a..2db09d0 100644 --- a/lib/ui/landing/dashboard_screen.dart +++ b/lib/ui/landing/dashboard_screen.dart @@ -162,7 +162,20 @@ class _DashboardScreenState extends State with WidgetsBindingOb if (val!.result!.data != null) { print("-------------------- Survey ----------------------------"); if (val.result!.data!.notificationType == "Survey") { - Navigator.pushNamed(context, AppRoutes.survey, arguments: val.result!.data); + DashboardApiClient().getAdvertisementDetail(val.result!.data!.notificationMasterId ?? "").then( + (value) { + if (value!.mohemmItgResponseItem!.statusCode == 200) { + if (value.mohemmItgResponseItem!.result!.data != null) { + // Navigator.pushNamed(context, AppRoutes.survey, arguments: val.result!.data); + Navigator.pushNamed(context, AppRoutes.survey, arguments: value.mohemmItgResponseItem!.result!.data); + // Navigator.pushNamed(context, AppRoutes.advertisement, arguments: { + // "masterId": val.result!.data!.notificationMasterId, + // "advertisement": value.mohemmItgResponseItem!.result!.data!.advertisement, + // }); + } + } + }, + ); } else { print("------------------------------------------- Ads --------------------"); DashboardApiClient().getAdvertisementDetail(val.result!.data!.notificationMasterId ?? "").then( diff --git a/lib/ui/landing/itg/survey_screen.dart b/lib/ui/landing/itg/survey_screen.dart index 6240934..a212f92 100644 --- a/lib/ui/landing/itg/survey_screen.dart +++ b/lib/ui/landing/itg/survey_screen.dart @@ -1,5 +1,3 @@ -import 'dart:convert'; - import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_rating_bar/flutter_rating_bar.dart'; @@ -7,15 +5,14 @@ import 'package:flutter_svg/flutter_svg.dart'; import 'package:mohem_flutter_app/api/dashboard_api_client.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; import 'package:mohem_flutter_app/classes/utils.dart'; -import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/extensions/int_extensions.dart'; import 'package:mohem_flutter_app/extensions/string_extensions.dart'; import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; import 'package:mohem_flutter_app/models/itg/itg_main_response.dart'; import 'package:mohem_flutter_app/models/itg/itg_response_model.dart'; +import 'package:mohem_flutter_app/models/itg/survey_model.dart'; import 'package:mohem_flutter_app/widgets/button/default_button.dart'; -import 'package:mohem_flutter_app/widgets/dynamic_forms/dynamic_textfield_widget.dart'; class SurveyScreen extends StatefulWidget { const SurveyScreen({Key? key}) : super(key: key); @@ -31,75 +28,98 @@ class _SurveyScreenState extends State { ItgResponseData? itgResponseData; + List answeredQuestions = []; + + @override + void initState() { + WidgetsBinding.instance.addPostFrameCallback( + (_) => initAnswersList(), + ); + super.initState(); + } + @override Widget build(BuildContext context) { - if (itgResponseData == null) itgResponseData = ModalRoute.of(context)!.settings.arguments as ItgResponseData; + itgResponseData ??= ModalRoute.of(context)!.settings.arguments as ItgResponseData; return Scaffold( backgroundColor: MyColors.backgroundColor, body: Column( children: [ Expanded( - child: ListView( - scrollDirection: Axis.vertical, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - 124.height, - LocaleKeys.feedbackUserExperience.tr().toText19(), - 27.height, - LocaleKeys.rateUI.tr().toText16(), - 22.height, - Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - RatingBar.builder( - initialRating: 3, - minRating: starRating, - direction: Axis.horizontal, - allowHalfRating: false, - itemCount: 5, - itemPadding: EdgeInsets.symmetric(horizontal: 8), - itemBuilder: (context, _) => Icon( - Icons.star, - color: Colors.amber, - ), - onRatingUpdate: (rating) { - starRating = rating; - }, - ) - ], - ).paddingOnly(left: 22, right: 22, top: 12, bottom: 12).objectContainerView(disablePadding: true), - 39.height, - LocaleKeys.rateUI2.tr().toText16(), - 10.height, - GridView( - gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 5, crossAxisSpacing: 7, mainAxisSpacing: 7), - physics: const NeverScrollableScrollPhysics(), - padding: const EdgeInsets.only(top: 0), - shrinkWrap: true, - children: [ - optionUI("poor.svg", 1), - optionUI("bad.svg", 2), - optionUI("normal.svg", 3), - optionUI("good.svg", 4), - optionUI("xcellent.svg", 5), - ], - ), - 27.height, - DynamicTextFieldWidget( - LocaleKeys.description.tr(), - LocaleKeys.typeHere.tr(), - lines: 3, - onChange: (v) { - reviewText = v; - }, - ), - 150.height - ], - ).paddingOnly(left: 21, right: 21), - ], + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + // crossAxisAlignment: CrossAxisAlignment.start, + children: [ + 32.height, + itgResponseData?.survey?.title?.toText24() ?? const Text(""), + 8.height, + itgResponseData?.survey?.description?.toText16() ?? const Text(""), + + ListView.builder( + padding: EdgeInsets.zero, + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemCount: itgResponseData?.survey?.questions?.length, + itemBuilder: (cxt, index) { + // return itgResponseData?.survey?.questions?[index].title?.toText14() ?? const Text(""); + return answeredQuestions.isNotEmpty ? getSurveyWidget(itgResponseData?.survey?.questions![index], index) : Container(); + }, + ), + + // LocaleKeys.feedbackUserExperience.tr().toText19(), + // 27.height, + // LocaleKeys.rateUI.tr().toText16(), + // 22.height, + // Row( + // crossAxisAlignment: CrossAxisAlignment.center, + // mainAxisAlignment: MainAxisAlignment.center, + // children: [ + // RatingBar.builder( + // initialRating: 3, + // minRating: starRating, + // direction: Axis.horizontal, + // allowHalfRating: false, + // itemCount: 5, + // itemPadding: EdgeInsets.symmetric(horizontal: 8), + // itemBuilder: (context, _) => Icon( + // Icons.star, + // color: Colors.amber, + // ), + // onRatingUpdate: (rating) { + // starRating = rating; + // }, + // ) + // ], + // ).paddingOnly(left: 22, right: 22, top: 12, bottom: 12).objectContainerView(disablePadding: true), + // 39.height, + // LocaleKeys.rateUI2.tr().toText16(), + // 10.height, + // GridView( + // gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 5, crossAxisSpacing: 7, mainAxisSpacing: 7), + // physics: const NeverScrollableScrollPhysics(), + // padding: const EdgeInsets.only(top: 0), + // shrinkWrap: true, + // children: [ + // optionUI("poor.svg", 1), + // optionUI("bad.svg", 2), + // optionUI("normal.svg", 3), + // optionUI("good.svg", 4), + // optionUI("xcellent.svg", 5), + // ], + // ), + // 27.height, + // DynamicTextFieldWidget( + // LocaleKeys.description.tr(), + // LocaleKeys.typeHere.tr(), + // lines: 3, + // onChange: (v) { + // reviewText = v; + // }, + // ), + // 150.height + ], + ).paddingOnly(left: 21, right: 21), )), DefaultButton( LocaleKeys.submitSurvey.tr(), @@ -111,7 +131,7 @@ class _SurveyScreenState extends State { )); } - Widget optionUI(String icon, int index) { + Widget optionUI(String icon, int? index, int answerIndex) { return (_selectedIndex == index ? SvgPicture.asset( 'assets/images/' + icon, @@ -126,22 +146,131 @@ class _SurveyScreenState extends State { disablePadding: true, )) .onPress(() { - _selectedIndex = index; + _selectedIndex = index!; + answeredQuestions[answerIndex] = _selectedIndex.toString(); setState(() {}); }); } + void initAnswersList() { + answeredQuestions.clear(); + itgResponseData?.survey?.questions?.forEach((element) { + if (element.type != "Stars") { + answeredQuestions.add(element.options![0].optionId.toString()); + } else { + answeredQuestions.add("3"); + } + }); + setState(() {}); + } + + Widget getSurveyWidget(Questions? question, int parentIndex) { + if (question?.type == "Expressions") { + // Expressions = radio buttons + return Column( + children: [ + 24.height, + question?.title?.toText18() ?? const Text(""), + 16.height, + Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + SizedBox( + height: 50.0, + child: ListView.builder( + scrollDirection: Axis.horizontal, + padding: EdgeInsets.zero, + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemCount: question?.options?.length, + itemBuilder: (cxt, index) { + return radioOption(question?.options?[index].title ?? "", question?.options?[index].optionId.toString() ?? "", answeredQuestions[parentIndex], parentIndex); + }, + ), + ), + ], + ).paddingOnly(left: 22, right: 22, top: 12, bottom: 12).objectContainerView(disablePadding: true), + ], + ); + } else if (question?.type == "Stars") { + // Stars = star rating + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + 24.height, + question?.title?.toText18() ?? Text(""), + 16.height, + RatingBar.builder( + initialRating: 3, + minRating: starRating, + direction: Axis.horizontal, + allowHalfRating: false, + itemCount: 5, + itemPadding: EdgeInsets.symmetric(horizontal: 8), + itemBuilder: (context, _) => Icon( + Icons.star, + color: Colors.amber, + ), + onRatingUpdate: (rating) { + starRating = rating; + answeredQuestions[parentIndex] = rating.toInt().toString(); + }, + ).paddingOnly(left: 22, right: 22, top: 12, bottom: 12).objectContainerView(disablePadding: true), + ], + ); + } else if (question?.type == "Faces") { + // Faces = face rating + return Column( + mainAxisSize: MainAxisSize.min, + children: [ + 24.height, + question?.title?.toText18() ?? Text("asdasdasdasd"), + 16.height, + GridView( + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 5, crossAxisSpacing: 7, mainAxisSpacing: 7), + physics: const NeverScrollableScrollPhysics(), + padding: const EdgeInsets.only(top: 0), + shrinkWrap: true, + children: [ + optionUI("poor.svg", question?.options?[0].optionId, parentIndex), + optionUI("bad.svg", question?.options?[1].optionId, parentIndex), + optionUI("normal.svg", question?.options?[2].optionId, parentIndex), + optionUI("good.svg", question?.options?[3].optionId, parentIndex), + optionUI("xcellent.svg", question?.options?[4].optionId, parentIndex), + ], + ), + ], + ); + } else { + return Container(); + } + return Container(); + } + void performAPI() async { Utils.showLoading(context); + List> itgAnswersList = []; + int index = 0; try { + answeredQuestions.forEach((element) { + itgAnswersList.add({ + "questionId": itgResponseData?.survey?.questions![index].questionId, + "optionId": itgResponseData?.survey?.questions![index].type != "Stars" ? answeredQuestions[index] : null, + "starRating": itgResponseData?.survey?.questions![index].type == "Stars" ? answeredQuestions[index] : null + }); + index++; + }); + ItgMainRes? res = await DashboardApiClient().submitItgForm( comment: reviewText, masterId: itgResponseData!.notificationMasterId ?? "", - itgList: [ - {"questionId": "1", "optionId": null, "starRating": starRating}, - {"questionId": "2", "optionId": "4", "starRating": _selectedIndex} - ], - serviceId: itgResponseData!.serviceId ?? 0); + // itgList: [ + // {"questionId": "1", "optionId": null, "starRating": starRating}, + // {"questionId": "2", "optionId": "4", "starRating": _selectedIndex} + // ], + itgList: itgAnswersList, + serviceId: itgResponseData!.survey!.surveyId ?? 0); Utils.hideLoading(context); if (res!.mohemmItgResponseItem!.statusCode == 200) { @@ -157,4 +286,39 @@ class _SurveyScreenState extends State { }); } } + + Widget radioOption(String title, String value, String groupValue, int answerIndex) { + return Row( + children: [ + Container( + width: 24, + height: 24, + decoration: BoxDecoration( + color: Colors.transparent, + border: Border.all(color: MyColors.borderColor, width: 1), + borderRadius: const BorderRadius.all( + Radius.circular(100), + ), + ), + padding: const EdgeInsets.all(4), + child: Container( + width: double.infinity, + height: double.infinity, + decoration: BoxDecoration( + color: value == answeredQuestions[answerIndex] ? MyColors.greenColor : Colors.transparent, + borderRadius: const BorderRadius.all( + Radius.circular(100), + ), + ), + ), + ), + 6.width, + title.toText12(color: MyColors.grey57Color), + 12.width + ], + ).onPress(() { + answeredQuestions[answerIndex] = value; + setState(() {}); + }); + } } diff --git a/lib/ui/work_list/item_history_screen.dart b/lib/ui/work_list/item_history_screen.dart index 7bc39fb..88abf06 100644 --- a/lib/ui/work_list/item_history_screen.dart +++ b/lib/ui/work_list/item_history_screen.dart @@ -329,7 +329,18 @@ class _ItemHistoryScreenState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ actionHistory.nAME!.toText16(), - if ((actionHistory.nOTE ?? "").isNotEmpty) "Note: ${actionHistory.nOTE!}".toText12(color: MyColors.grey57Color), + if ((actionHistory.nOTE ?? "").isNotEmpty) + SelectableText( + actionHistory.nOTE!, + style: const TextStyle( + fontSize: 12, + fontWeight: FontWeight.w600, + color: MyColors.grey57Color, + letterSpacing: -0.72, + ), + ), + + // "Note: ${actionHistory.nOTE!}".toText12(color: MyColors.grey57Color), 4.height, Row( children: [ diff --git a/lib/ui/work_list/worklist_fragments/actions_fragment.dart b/lib/ui/work_list/worklist_fragments/actions_fragment.dart index 98b5b72..1d88129 100644 --- a/lib/ui/work_list/worklist_fragments/actions_fragment.dart +++ b/lib/ui/work_list/worklist_fragments/actions_fragment.dart @@ -82,7 +82,20 @@ class ActionsFragment extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ actionHistory.nAME!.toText16(), - if ((actionHistory.nOTE ?? "").isNotEmpty) "Note: ${actionHistory.nOTE!}".toText12(color: MyColors.grey57Color), + + if ((actionHistory.nOTE ?? "").isNotEmpty) + SelectableText( + actionHistory.nOTE!, + style: const TextStyle( + fontSize: 12, + fontWeight: FontWeight.w600, + color: MyColors.grey57Color, + letterSpacing: -0.72, + ), + ), + + // if ((actionHistory.nOTE ?? "").isNotEmpty) "Note: ${actionHistory.nOTE!}".toText12(color: MyColors.grey57Color), + 4.height, Row( children: [ diff --git a/lib/widgets/mark_attendance_widget.dart b/lib/widgets/mark_attendance_widget.dart index 8a52a78..f11fafe 100644 --- a/lib/widgets/mark_attendance_widget.dart +++ b/lib/widgets/mark_attendance_widget.dart @@ -26,6 +26,7 @@ import 'package:mohem_flutter_app/widgets/nfc/nfc_reader_sheet.dart'; import 'package:mohem_flutter_app/widgets/qr_scanner_dialog.dart'; import 'package:nfc_manager/nfc_manager.dart'; import 'package:permission_handler/permission_handler.dart'; +import 'package:platform_device_id/platform_device_id.dart'; import 'package:wifi_iot/wifi_iot.dart'; class MarkAttendanceWidget extends StatefulWidget { @@ -53,6 +54,8 @@ class _MarkAttendanceWidgetState extends State { } void checkAttendanceAvailability() async { + String? deviceID = await PlatformDeviceId.getDeviceId; + print("Platform Device ID: $deviceID"); bool isAvailable = await NfcManager.instance.isAvailable(); setState(() { AppState().privilegeListModel!.forEach((PrivilegeListModel element) { @@ -131,7 +134,7 @@ class _MarkAttendanceWidgetState extends State { children: [ // if (isNfcEnabled) attendanceMethod("NFC", "assets/images/nfc.svg", isNfcEnabled, () { - if (isNfcLocationEnabled) { + // if (isNfcLocationEnabled) { if (AppState().getIsHuawei) { checkHuaweiLocationPermission("NFC"); } else { @@ -143,13 +146,13 @@ class _MarkAttendanceWidgetState extends State { } }, context); } - } else { - performNfcAttendance(widget.model); - } + // } else { + // performNfcAttendance(widget.model); + // } }), if (isWifiEnabled) attendanceMethod("Wifi", "assets/images/wufu.svg", isWifiEnabled, () { - if (isWifiLocationEnabled) { + // if (isWifiLocationEnabled) { if (AppState().getIsHuawei) { checkHuaweiLocationPermission("WIFI"); } else { @@ -161,13 +164,13 @@ class _MarkAttendanceWidgetState extends State { } }, context); } - } else { - performWifiAttendance(widget.model); - } + // } else { + // performWifiAttendance(widget.model); + // } }), if (isQrEnabled) attendanceMethod("QR", "assets/images/ic_qr.svg", isQrEnabled, () async { - if (isQrLocationEnabled) { + // if (isQrLocationEnabled) { if (AppState().getIsHuawei) { checkHuaweiLocationPermission("QR"); } else { @@ -179,9 +182,9 @@ class _MarkAttendanceWidgetState extends State { } }, context); } - } else { - performQrCodeAttendance(widget.model); - } + // } else { + // performQrCodeAttendance(widget.model); + // } // performQrCodeAttendance(model); }), ], From 1f369e912253e34e01315b75d4a2fe2d26d2109e Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Wed, 5 Apr 2023 14:40:33 +0300 Subject: [PATCH 2/3] survey updates --- lib/ui/landing/itg/survey_screen.dart | 149 ++++++++------------------ 1 file changed, 45 insertions(+), 104 deletions(-) diff --git a/lib/ui/landing/itg/survey_screen.dart b/lib/ui/landing/itg/survey_screen.dart index a212f92..fce206f 100644 --- a/lib/ui/landing/itg/survey_screen.dart +++ b/lib/ui/landing/itg/survey_screen.dart @@ -24,7 +24,7 @@ class SurveyScreen extends StatefulWidget { class _SurveyScreenState extends State { String reviewText = ""; double starRating = 1; - int _selectedIndex = 5; + int _selectedIndex = 0; ItgResponseData? itgResponseData; @@ -46,80 +46,29 @@ class _SurveyScreenState extends State { body: Column( children: [ Expanded( - child: Padding( - padding: const EdgeInsets.all(16.0), - child: Column( - // crossAxisAlignment: CrossAxisAlignment.start, - children: [ - 32.height, - itgResponseData?.survey?.title?.toText24() ?? const Text(""), - 8.height, - itgResponseData?.survey?.description?.toText16() ?? const Text(""), - - ListView.builder( - padding: EdgeInsets.zero, - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - itemCount: itgResponseData?.survey?.questions?.length, - itemBuilder: (cxt, index) { - // return itgResponseData?.survey?.questions?[index].title?.toText14() ?? const Text(""); - return answeredQuestions.isNotEmpty ? getSurveyWidget(itgResponseData?.survey?.questions![index], index) : Container(); - }, - ), - - // LocaleKeys.feedbackUserExperience.tr().toText19(), - // 27.height, - // LocaleKeys.rateUI.tr().toText16(), - // 22.height, - // Row( - // crossAxisAlignment: CrossAxisAlignment.center, - // mainAxisAlignment: MainAxisAlignment.center, - // children: [ - // RatingBar.builder( - // initialRating: 3, - // minRating: starRating, - // direction: Axis.horizontal, - // allowHalfRating: false, - // itemCount: 5, - // itemPadding: EdgeInsets.symmetric(horizontal: 8), - // itemBuilder: (context, _) => Icon( - // Icons.star, - // color: Colors.amber, - // ), - // onRatingUpdate: (rating) { - // starRating = rating; - // }, - // ) - // ], - // ).paddingOnly(left: 22, right: 22, top: 12, bottom: 12).objectContainerView(disablePadding: true), - // 39.height, - // LocaleKeys.rateUI2.tr().toText16(), - // 10.height, - // GridView( - // gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 5, crossAxisSpacing: 7, mainAxisSpacing: 7), - // physics: const NeverScrollableScrollPhysics(), - // padding: const EdgeInsets.only(top: 0), - // shrinkWrap: true, - // children: [ - // optionUI("poor.svg", 1), - // optionUI("bad.svg", 2), - // optionUI("normal.svg", 3), - // optionUI("good.svg", 4), - // optionUI("xcellent.svg", 5), - // ], - // ), - // 27.height, - // DynamicTextFieldWidget( - // LocaleKeys.description.tr(), - // LocaleKeys.typeHere.tr(), - // lines: 3, - // onChange: (v) { - // reviewText = v; - // }, - // ), - // 150.height - ], - ).paddingOnly(left: 21, right: 21), + child: ListView( + children: [ + Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + children: [ + 32.height, + itgResponseData?.survey?.title?.toText24() ?? const Text(""), + 8.height, + itgResponseData?.survey?.description?.toText16() ?? const Text(""), + ListView.builder( + padding: EdgeInsets.zero, + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemCount: itgResponseData?.survey?.questions?.length, + itemBuilder: (cxt, index) { + return answeredQuestions.isNotEmpty ? getSurveyWidget(itgResponseData?.survey?.questions![index], index) : Container(); + }, + ), + ], + ).paddingOnly(left: 21, right: 21), + ), + ], )), DefaultButton( LocaleKeys.submitSurvey.tr(), @@ -156,6 +105,9 @@ class _SurveyScreenState extends State { answeredQuestions.clear(); itgResponseData?.survey?.questions?.forEach((element) { if (element.type != "Stars") { + if(element.type == "Faces") { + _selectedIndex = element.options![0].optionId!; + } answeredQuestions.add(element.options![0].optionId.toString()); } else { answeredQuestions.add("3"); @@ -172,24 +124,18 @@ class _SurveyScreenState extends State { 24.height, question?.title?.toText18() ?? const Text(""), 16.height, - Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SizedBox( - height: 50.0, - child: ListView.builder( - scrollDirection: Axis.horizontal, - padding: EdgeInsets.zero, - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - itemCount: question?.options?.length, - itemBuilder: (cxt, index) { - return radioOption(question?.options?[index].title ?? "", question?.options?[index].optionId.toString() ?? "", answeredQuestions[parentIndex], parentIndex); - }, - ), - ), - ], + GridView.builder( + padding: EdgeInsets.zero, + itemCount: question?.options?.length, + shrinkWrap: true, + physics: const NeverScrollableScrollPhysics(), + itemBuilder: (context, index) { + return radioOption(question?.options?[index].title ?? "", question?.options?[index].optionId.toString() ?? "", answeredQuestions[parentIndex], parentIndex); + }, + gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount( + crossAxisCount: 2, + childAspectRatio: (4.0), + ), ).paddingOnly(left: 22, right: 22, top: 12, bottom: 12).objectContainerView(disablePadding: true), ], ); @@ -207,8 +153,8 @@ class _SurveyScreenState extends State { direction: Axis.horizontal, allowHalfRating: false, itemCount: 5, - itemPadding: EdgeInsets.symmetric(horizontal: 8), - itemBuilder: (context, _) => Icon( + itemPadding: const EdgeInsets.symmetric(horizontal: 8), + itemBuilder: (context, _) => const Icon( Icons.star, color: Colors.amber, ), @@ -262,15 +208,8 @@ class _SurveyScreenState extends State { index++; }); - ItgMainRes? res = await DashboardApiClient().submitItgForm( - comment: reviewText, - masterId: itgResponseData!.notificationMasterId ?? "", - // itgList: [ - // {"questionId": "1", "optionId": null, "starRating": starRating}, - // {"questionId": "2", "optionId": "4", "starRating": _selectedIndex} - // ], - itgList: itgAnswersList, - serviceId: itgResponseData!.survey!.surveyId ?? 0); + ItgMainRes? res = await DashboardApiClient() + .submitItgForm(comment: reviewText, masterId: itgResponseData!.notificationMasterId ?? "", itgList: itgAnswersList, serviceId: itgResponseData!.survey!.surveyId ?? 0); Utils.hideLoading(context); if (res!.mohemmItgResponseItem!.statusCode == 200) { @@ -289,6 +228,8 @@ class _SurveyScreenState extends State { Widget radioOption(String title, String value, String groupValue, int answerIndex) { return Row( + mainAxisAlignment: MainAxisAlignment.start, + mainAxisSize: MainAxisSize.min, children: [ Container( width: 24, From 45fdb4a466343d03c232adc42a7a3da75cd9e8c8 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Sun, 9 Apr 2023 15:51:21 +0300 Subject: [PATCH 3/3] updates --- lib/ui/landing/itg/survey_screen.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ui/landing/itg/survey_screen.dart b/lib/ui/landing/itg/survey_screen.dart index fce206f..59f3c14 100644 --- a/lib/ui/landing/itg/survey_screen.dart +++ b/lib/ui/landing/itg/survey_screen.dart @@ -110,7 +110,7 @@ class _SurveyScreenState extends State { } answeredQuestions.add(element.options![0].optionId.toString()); } else { - answeredQuestions.add("3"); + answeredQuestions.add("4"); } }); setState(() {});