Skip to content

Commit 767c5e4

Browse files
saiful-apxadar2378
andauthored
Added MultipleChoiceAutoCompleteAnswerView, other text field in MCQ answers (QuickBirdEng#92)
* added missing MultipleChoiceQuestionResult toJson * Updated PlatformAppbar with default AppBar widget * Updated IconButton -> BackButton * Added other field in Multiple choice answers * added Multiple choice autocomplete * Customized the builder * added comment * DRY refactor * Updated other field label behavior * Added clear button and added tick mark check on dropdown * Updated example Co-authored-by: Adar <[email protected]> Co-authored-by: saiful_apx <[email protected]>
1 parent 6ad765a commit 767c5e4

11 files changed

+479
-20
lines changed

example/assets/example_json.json

+63-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
22
"id": "123",
33
"type": "navigable",
4-
"rules": [
5-
{
4+
"rules": [{
65
"type": "conditional",
76
"triggerStepIdentifier": {
87
"id": "7"
@@ -53,8 +52,7 @@
5352
}
5453
}
5554
],
56-
"steps": [
57-
{
55+
"steps": [{
5856
"stepIdentifier": {
5957
"id": "1"
6058
},
@@ -126,8 +124,7 @@
126124
"title": "Known allergies",
127125
"answerFormat": {
128126
"type": "multiple",
129-
"textChoices": [
130-
{
127+
"textChoices": [{
131128
"text": "Penicillin",
132129
"value": "Penicillin"
133130
},
@@ -155,8 +152,7 @@
155152
"text": "We are done, do you mind to tell us more about yourself?",
156153
"answerFormat": {
157154
"type": "single",
158-
"textChoices": [
159-
{
155+
"textChoices": [{
160156
"text": "Yes",
161157
"value": "Yes"
162158
},
@@ -194,6 +190,64 @@
194190
"defaultDate": "2021-06-25T04:08:16Z"
195191
}
196192
},
193+
{
194+
"stepIdentifier": {
195+
"id": "12"
196+
},
197+
"type": "question",
198+
"title": "Known allergies",
199+
"answerFormat": {
200+
"type": "multiple",
201+
"otherField": true,
202+
"textChoices": [{
203+
"text": "Penicillin",
204+
"value": "Penicillin"
205+
},
206+
{
207+
"text": "Latex",
208+
"value": "Latex"
209+
},
210+
{
211+
"text": "Pet",
212+
"value": "Pet"
213+
},
214+
{
215+
"text": "Pollen",
216+
"value": "Pollen"
217+
}
218+
]
219+
}
220+
},
221+
{
222+
"stepIdentifier": {
223+
"id": "13"
224+
},
225+
"type": "question",
226+
"title": "Medicines",
227+
"answerFormat": {
228+
"type": "multiple_auto_complete",
229+
"otherField": true,
230+
"textChoices": [{
231+
"text": "Penicillin",
232+
"value": "Penicillin"
233+
},
234+
{
235+
"text": "Latex",
236+
"value": "Latex"
237+
}
238+
239+
],
240+
"suggestions": [{
241+
"text": "Pet",
242+
"value": "Pet"
243+
},
244+
{
245+
"text": "Pollen",
246+
"value": "Pollen"
247+
}
248+
]
249+
}
250+
},
197251
{
198252
"stepIdentifier": {
199253
"id": "10"
@@ -212,8 +266,7 @@
212266
"text": "What type of pet(s) do you have?",
213267
"answerFormat": {
214268
"type": "multiple",
215-
"textChoices": [
216-
{
269+
"textChoices": [{
217270
"text": "Dog",
218271
"value": "Dog"
219272
},

lib/src/answer_format/answer_format.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import 'package:survey_kit/src/answer_format/boolean_answer_format.dart';
44
import 'package:survey_kit/src/answer_format/date_answer_format.dart';
55
import 'package:survey_kit/src/answer_format/double_answer_format.dart';
6+
import 'package:survey_kit/src/answer_format/multiple_choice_auto_complete_answer_format.dart';
7+
import 'package:survey_kit/src/answer_format/multiple_double_answer_format.dart';
68
import 'package:survey_kit/src/answer_format/image_answer_format.dart';
79
import 'package:survey_kit/src/answer_format/integer_answer_format.dart';
810
import 'package:survey_kit/src/answer_format/multiple_choice_answer_format.dart';
9-
import 'package:survey_kit/src/answer_format/multiple_double_answer_format.dart';
1011
import 'package:survey_kit/src/answer_format/scale_answer_format.dart';
1112
import 'package:survey_kit/src/answer_format/single_choice_answer_format.dart';
1213
import 'package:survey_kit/src/answer_format/text_answer_format.dart';
@@ -34,6 +35,8 @@ abstract class AnswerFormat {
3435
return MultipleChoiceAnswerFormat.fromJson(json);
3536
case 'multiple_double':
3637
return MultipleDoubleAnswerFormat.fromJson(json);
38+
case 'multiple_auto_complete':
39+
return MultipleChoiceAutoCompleteAnswerFormat.fromJson(json);
3740
case 'scale':
3841
return ScaleAnswerFormat.fromJson(json);
3942
case 'time':

lib/src/answer_format/multiple_choice_answer_format.dart

+3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ class MultipleChoiceAnswerFormat implements AnswerFormat {
99
final List<TextChoice> textChoices;
1010
@JsonKey(defaultValue: const [])
1111
final List<TextChoice> defaultSelection;
12+
@JsonKey(defaultValue: false)
13+
final bool otherField;
1214

1315
const MultipleChoiceAnswerFormat({
1416
required this.textChoices,
1517
this.defaultSelection = const [],
18+
this.otherField = false,
1619
}) : super();
1720

1821
factory MultipleChoiceAnswerFormat.fromJson(Map<String, dynamic> json) =>

lib/src/answer_format/multiple_choice_answer_format.g.dart

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import 'package:json_annotation/json_annotation.dart';
2+
import 'package:survey_kit/src/answer_format/answer_format.dart';
3+
import 'package:survey_kit/src/answer_format/text_choice.dart';
4+
5+
part 'multiple_choice_auto_complete_answer_format.g.dart';
6+
7+
@JsonSerializable()
8+
class MultipleChoiceAutoCompleteAnswerFormat implements AnswerFormat {
9+
final List<TextChoice> textChoices;
10+
@JsonKey(defaultValue: const [])
11+
final List<TextChoice> defaultSelection;
12+
@JsonKey(defaultValue: const [])
13+
final List<TextChoice> suggestions;
14+
@JsonKey(defaultValue: false)
15+
final bool otherField;
16+
17+
const MultipleChoiceAutoCompleteAnswerFormat({
18+
required this.textChoices,
19+
this.defaultSelection = const [],
20+
this.suggestions = const [],
21+
this.otherField = false,
22+
}) : super();
23+
24+
factory MultipleChoiceAutoCompleteAnswerFormat.fromJson(
25+
Map<String, dynamic> json) =>
26+
_$MultipleChoiceAutoCompleteAnswerFormatFromJson(json);
27+
Map<String, dynamic> toJson() =>
28+
_$MultipleChoiceAutoCompleteAnswerFormatToJson(this);
29+
}

lib/src/answer_format/multiple_choice_auto_complete_answer_format.g.dart

+34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/result/question/multiple_choice_question_result.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class MultipleChoiceQuestionResult extends QuestionResult<List<TextChoice>?> {
2222
result: result,
2323
);
2424

25-
factory MultipleChoiceQuestionResult.fromJson(Map<String, dynamic> json) => _$MultipleChoiceQuestionResultFromJson(json);
25+
factory MultipleChoiceQuestionResult.fromJson(Map<String, dynamic> json) =>
26+
_$MultipleChoiceQuestionResultFromJson(json);
2627

2728
Map<String, dynamic> toJson() => _$MultipleChoiceQuestionResultToJson(this);
2829

lib/src/steps/predefined_steps/question_step.dart

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:survey_kit/src/answer_format/double_answer_format.dart';
77
import 'package:survey_kit/src/answer_format/image_answer_format.dart';
88
import 'package:survey_kit/src/answer_format/integer_answer_format.dart';
99
import 'package:survey_kit/src/answer_format/multiple_choice_answer_format.dart';
10+
import 'package:survey_kit/src/answer_format/multiple_choice_auto_complete_answer_format.dart';
1011
import 'package:survey_kit/src/answer_format/multiple_double_answer_format.dart';
1112
import 'package:survey_kit/src/answer_format/scale_answer_format.dart';
1213
import 'package:survey_kit/src/answer_format/single_choice_answer_format.dart';
@@ -30,6 +31,7 @@ import 'package:survey_kit/src/steps/step.dart';
3031
import 'package:survey_kit/src/views/boolean_answer_view.dart';
3132
import 'package:survey_kit/src/views/date_answer_view.dart';
3233
import 'package:survey_kit/src/views/double_answer_view.dart';
34+
import 'package:survey_kit/src/views/multiple_auto_complete_answer_view.dart';
3335
import 'package:survey_kit/src/views/image_answer_view.dart';
3436
import 'package:survey_kit/src/views/integer_answer_view.dart';
3537
import 'package:survey_kit/src/views/multiple_choice_answer_view.dart';
@@ -133,6 +135,12 @@ class QuestionStep extends Step {
133135
questionStep: this,
134136
result: questionResult as MultipleDoubleQuestionResult?,
135137
);
138+
case MultipleChoiceAutoCompleteAnswerFormat:
139+
return MultipleChoiceAutoCompleteAnswerView(
140+
key: key,
141+
questionStep: this,
142+
result: questionResult as MultipleChoiceQuestionResult?,
143+
);
136144
case ImageAnswerFormat:
137145
return ImageAnswerView(
138146
key: key,

0 commit comments

Comments
 (0)