survey improvements.

design_3.0_cx_module
Sikander Saleem 2 months ago
parent 9d7c3a38b2
commit a902204ff1

@ -42,7 +42,9 @@ class ApiManager {
if (jsonDecode(response.body) is Map<String, dynamic>) {
final message = jsonDecode(response.body)["message"];
if (message != null && message.toString().isNotEmpty) {
Fluttertoast.showToast(msg: message ?? "", toastLength: Toast.LENGTH_LONG);
if (enableToastMessage) {
Fluttertoast.showToast(msg: message ?? "", toastLength: Toast.LENGTH_LONG);
}
}
}
}

@ -31,9 +31,9 @@ extension BuildContextExtension on BuildContext {
void showConfirmDialog(String message, {String? title, VoidCallback? onTap}) => showDialog(
void showConfirmDialog(String message, {String? title, VoidCallback? onTap, String? okTitle}) => showDialog(
context: this,
builder: (BuildContext cxt) => ConfirmDialog(message: message, onTap: onTap, title: title),
builder: (BuildContext cxt) => ConfirmDialog(message: message, onTap: onTap, title: title,okTitle: okTitle),
);
Future showBottomSheet(Widget childWidget, {bool? isDismissible, String? title}) => showModalBottomSheet(

@ -34,6 +34,7 @@ class _SurveyPageState extends State<SurveyPage> {
// int serviceSatisfiedRating = -1;
int serviceProvidedRating = -1;
String comments = "";
String message = "";
bool loading = false;
@ -50,7 +51,10 @@ class _SurveyPageState extends State<SurveyPage> {
void getSurveyQuestion() async {
loading = true;
setState(() {});
questionnaire = await Provider.of<SurveyProvider>(context, listen: false).getQuestionnaire(widget.surveyId);
await Provider.of<SurveyProvider>(context, listen: false).getQuestionnaire(widget.surveyId, (msg, questions) {
message = msg;
questionnaire = questions;
});
for (int i = 0; i < (questionnaire?.surveyQuestions?.length ?? 0); i++) {
answers.add(SurveyAnswers(
questionId: questionnaire!.surveyQuestions![i].questionId!,
@ -79,18 +83,18 @@ class _SurveyPageState extends State<SurveyPage> {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"Failed to get questionnaire",
message.isNotEmpty ? message : "Failed to get questionnaire",
overflow: TextOverflow.ellipsis,
maxLines: 1,
style: AppTextStyles.heading6.copyWith(color: AppColor.neutral50, fontWeight: FontWeight.w500),
),
24.height,
AppFilledButton(
label: "Retry",
label: message.isNotEmpty ? "Go Back " : "Retry",
maxWidth: true,
buttonColor: AppColor.primary10,
onPressed: () {
getSurveyQuestion();
message.isNotEmpty ? Navigator.pop(context) : getSurveyQuestion();
},
).paddingOnly(start: 48, end: 48)
],
@ -171,7 +175,10 @@ class _SurveyPageState extends State<SurveyPage> {
bool isSuccess = await Provider.of<SurveyProvider>(context, listen: false).submitQuestionare(payload);
Utils.hideLoading(context);
if (isSuccess) {
//getSurveyQuestion();
context.showConfirmDialog("Thank you for submitting the Feedback. It value for us to improve system and overall experience.", title: "Thanks!", okTitle: "Go Back",
onTap: () {
Navigator.pop(context);
});
} //reload Data
}
},

@ -18,16 +18,24 @@ class SurveyProvider with ChangeNotifier {
// ChatApiClient().chatLoginResponse = null;
}
Future<Questionnaire?> getQuestionnaire(int surveySubmissionId) async {
getQuestionnaire(int surveySubmissionId, Function(String message, Questionnaire? questionnaire) onResponse) async {
String responseMsg = "";
Questionnaire? q;
try {
final response = await ApiManager.instance.get("${URLs.getQuestionnaire.toString().replaceFirst("/mobile/", "/api/")}?surveySubmissionId=$surveySubmissionId");
final response = await ApiManager.instance.get("${URLs.getQuestionnaire.toString().replaceFirst("/mobile/", "/api/")}?surveySubmissionId=$surveySubmissionId", enableToastMessage: false);
if (response.statusCode >= 200 && response.statusCode < 300) {
return Questionnaire.fromJson(jsonDecode(response.body)["data"]);
if (jsonDecode(response.body)["message"] != null && jsonDecode(response.body)["message"].toString().isNotEmpty) {
responseMsg = jsonDecode(response.body)["message"];
} else {
q = Questionnaire.fromJson(jsonDecode(response.body)["data"]);
}
}
} catch (ex) {
"Failed, Retry.".showToast;
}
return null;
onResponse(responseMsg, q);
// return null;
}
Future<bool> submitQuestionare(Map<String, dynamic> payload) async {

@ -17,7 +17,7 @@ class ConfirmDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Dialog(
backgroundColor:AppColor.background(context),
backgroundColor: AppColor.background(context),
shape: const RoundedRectangleBorder(),
insetPadding: const EdgeInsets.only(left: 21, right: 21),
child: Padding(
@ -32,7 +32,7 @@ class ConfirmDialog extends StatelessWidget {
Expanded(
child: Text(
title ?? "Confirm",
style: TextStyle(fontSize: 24, fontWeight: FontWeight.w600, color: AppColor.headingTextColor(context), height: 35 / 24, letterSpacing: -0.96),
style: TextStyle(fontSize: 24, fontWeight: FontWeight.w600, color: AppColor.headingTextColor(context), height: 35 / 24, letterSpacing: -0.96),
).paddingOnly(top: 16),
),
IconButton(

Loading…
Cancel
Save