Skip to content

Commit 5817f14

Browse files
Gabriel SoaresGabriel Soares
andauthored
Image answer implementations (#117)
* insert of new implementations on image_answer_view and image_answer_format * Ajustments in the view and json reading * ajust on the deprecated function window * remove of unused import * ajustments in deprecated widget * Insert of image question result test --------- Co-authored-by: Gabriel Soares <[email protected]>
1 parent f608106 commit 5817f14

File tree

13 files changed

+159
-33
lines changed

13 files changed

+159
-33
lines changed

example/assets/example_json.json

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"id": "123",
33
"type": "navigable",
4-
"rules": [{
4+
"rules": [
5+
{
56
"type": "conditional",
67
"triggerStepIdentifier": {
78
"id": "7"
@@ -52,7 +53,8 @@
5253
}
5354
}
5455
],
55-
"steps": [{
56+
"steps": [
57+
{
5658
"stepIdentifier": {
5759
"id": "1"
5860
},
@@ -124,7 +126,8 @@
124126
"title": "Known allergies",
125127
"answerFormat": {
126128
"type": "multiple",
127-
"textChoices": [{
129+
"textChoices": [
130+
{
128131
"text": "Penicillin",
129132
"value": "Penicillin"
130133
},
@@ -152,7 +155,8 @@
152155
"text": "We are done, do you mind to tell us more about yourself?",
153156
"answerFormat": {
154157
"type": "single",
155-
"textChoices": [{
158+
"textChoices": [
159+
{
156160
"text": "Yes",
157161
"value": "Yes"
158162
},
@@ -199,7 +203,8 @@
199203
"answerFormat": {
200204
"type": "multiple",
201205
"otherField": true,
202-
"textChoices": [{
206+
"textChoices": [
207+
{
203208
"text": "Penicillin",
204209
"value": "Penicillin"
205210
},
@@ -227,17 +232,18 @@
227232
"answerFormat": {
228233
"type": "multiple_auto_complete",
229234
"otherField": true,
230-
"textChoices": [{
235+
"textChoices": [
236+
{
231237
"text": "Penicillin",
232238
"value": "Penicillin"
233239
},
234240
{
235241
"text": "Latex",
236242
"value": "Latex"
237243
}
238-
239244
],
240-
"suggestions": [{
245+
"suggestions": [
246+
{
241247
"text": "Pet",
242248
"value": "Pet"
243249
},
@@ -266,7 +272,8 @@
266272
"text": "What type of pet(s) do you have?",
267273
"answerFormat": {
268274
"type": "multiple",
269-
"textChoices": [{
275+
"textChoices": [
276+
{
270277
"text": "Dog",
271278
"value": "Dog"
272279
},
@@ -284,6 +291,21 @@
284291
}
285292
]
286293
}
294+
},
295+
{
296+
"stepIdentifier": {
297+
"id": "12"
298+
},
299+
"type": "question",
300+
"title": "Upload a selfie",
301+
"answerFormat": {
302+
"type": "file",
303+
"defaultValue": "https://www.maxicolor.com.br/wp-content/uploads/2019/11/placeholder-3x4-450x600.jpg",
304+
"buttonText": "Selfie",
305+
"useGallery": true,
306+
"hintImage": "https://www.maxicolor.com.br/wp-content/uploads/2019/11/placeholder-3x4-450x600.jpg",
307+
"hintTitle": "How the image should look"
308+
}
287309
}
288310
]
289-
}
311+
}

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 50;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -217,6 +217,7 @@
217217
};
218218
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
219219
isa = PBXShellScriptBuildPhase;
220+
alwaysOutOfDate = 1;
220221
buildActionMask = 2147483647;
221222
files = (
222223
);
@@ -231,6 +232,7 @@
231232
};
232233
9740EEB61CF901F6004384FC /* Run Script */ = {
233234
isa = PBXShellScriptBuildPhase;
235+
alwaysOutOfDate = 1;
234236
buildActionMask = 2147483647;
235237
files = (
236238
);

example/ios/Runner/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,7 @@
4848
</dict>
4949
<key>CADisableMinimumFrameDurationOnPhone</key>
5050
<true/>
51+
<key>UIApplicationSupportsIndirectInputEvents</key>
52+
<true/>
5153
</dict>
5254
</plist>

example/lib/main.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ class _MyAppState extends State<MyApp> {
250250
maxDate: DateTime.now(),
251251
),
252252
),
253+
QuestionStep(
254+
title: 'Upload a image of you',
255+
answerFormat: ImageAnswerFormat(
256+
buttonText: 'Upload your photo',
257+
useGallery: true,
258+
),
259+
),
253260
CompletionStep(
254261
stepIdentifier: StepIdentifier(id: '321'),
255262
text: 'Thanks for taking the survey, we will contact you soon!',

example/pubspec.lock

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ packages:
7070
name: characters
7171
url: "https://pub.dartlang.org"
7272
source: hosted
73-
version: "1.2.1"
73+
version: "1.3.0"
7474
clock:
7575
dependency: transitive
7676
description:
@@ -198,6 +198,11 @@ packages:
198198
description: flutter
199199
source: sdk
200200
version: "0.0.0"
201+
fuchsia_remote_debug_protocol:
202+
dependency: transitive
203+
description: flutter
204+
source: sdk
205+
version: "0.0.0"
201206
go_router:
202207
dependency: transitive
203208
description:
@@ -358,7 +363,15 @@ packages:
358363
name: path
359364
url: "https://pub.dartlang.org"
360365
source: hosted
361-
version: "1.8.2"
366+
version: "1.8.3"
367+
platform:
368+
dependency: transitive
369+
description:
370+
name: platform
371+
sha256: "4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76"
372+
url: "https://pub.dev"
373+
source: hosted
374+
version: "3.1.0"
362375
plugin_platform_interface:
363376
dependency: transitive
364377
description:
@@ -434,6 +447,14 @@ packages:
434447
relative: true
435448
source: path
436449
version: "0.1.2"
450+
sync_http:
451+
dependency: transitive
452+
description:
453+
name: sync_http
454+
sha256: "7f0cd72eca000d2e026bcd6f990b81d0ca06022ef4e32fb257b30d3d1014a961"
455+
url: "https://pub.dev"
456+
source: hosted
457+
version: "0.3.1"
437458
term_glyph:
438459
dependency: transitive
439460
description:

example/pubspec.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ description: Demonstrates how to use the surveykit plugin.
33

44
# The following line prevents the package from being accidentally published to
55
# pub.dev using `pub publish`. This is preferred for private packages.
6-
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
6+
publish_to: "none" # Remove this line if you wish to publish to pub.dev
77

88
environment:
9-
sdk: '>=2.12.0-0 <3.0.0'
9+
sdk: ">=2.12.0-0 <3.0.0"
1010

1111
dependencies:
1212
flutter:
@@ -20,25 +20,25 @@ dependencies:
2020
# the parent directory to use the current plugin's version.
2121
path: ../
2222

23-
2423
dev_dependencies:
2524
flutter_test:
2625
sdk: flutter
26+
integration_test:
27+
sdk: flutter
2728

2829
# For information on the generic Dart part of this file, see the
2930
# following page: https://dart.dev/tools/pub/pubspec
3031

3132
# The following section is specific to Flutter.
3233
flutter:
33-
3434
# The following line ensures that the Material Icons font is
3535
# included with your application, so that you can use the icons in
3636
# the material Icons class.
3737
uses-material-design: true
3838

3939
# To add assets to your application, add an assets section, like this:
4040
assets:
41-
- assets/example_json.json
41+
- assets/example_json.json
4242
# - images/a_dot_ham.jpeg
4343

4444
# An image asset can refer to one or more resolution-specific "variants", see

lib/src/answer_format/image_answer_format.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@ part 'image_answer_format.g.dart';
77
class ImageAnswerFormat implements AnswerFormat {
88
final String? defaultValue;
99
final String buttonText;
10+
final bool useGallery;
11+
final String? hintImage;
12+
final String? hintTitle;
1013

1114
const ImageAnswerFormat({
1215
this.defaultValue,
1316
this.buttonText = 'Image: ',
17+
this.useGallery = true,
18+
this.hintImage,
19+
this.hintTitle,
20+
1421
}) : super();
1522

1623
factory ImageAnswerFormat.fromJson(Map<String, dynamic> json) =>

lib/src/answer_format/image_answer_format.g.dart

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/src/views/image_answer_view.dart

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class _ImageAnswerViewState extends State<ImageAnswerView> {
6969
vertical: 8.0,
7070
),
7171
child: Row(
72-
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
72+
mainAxisAlignment: MainAxisAlignment.center,
7373
crossAxisAlignment: CrossAxisAlignment.center,
7474
children: [
7575
ElevatedButton(
@@ -113,16 +113,39 @@ class _ImageAnswerViewState extends State<ImageAnswerView> {
113113
GestureDetector(
114114
child: Text('Take a picture'),
115115
onTap: () {
116-
_openCamera();
116+
if (_imageAnswerFormat.hintImage != null &&
117+
_imageAnswerFormat.hintTitle != null) {
118+
showDialog(
119+
context: context,
120+
builder: (context) => AlertDialog(
121+
title: Text(
122+
_imageAnswerFormat.hintTitle.toString(),
123+
style: TextStyle(color: Colors.black),
124+
),
125+
content: Image.network(
126+
_imageAnswerFormat.hintImage.toString(),
127+
),
128+
actions: [
129+
TextButton(
130+
onPressed: () => _openCamera(),
131+
child: Text('Open Camera')),
132+
],
133+
),
134+
);
135+
} else {
136+
_openCamera();
137+
}
117138
},
118139
),
119140
Padding(padding: EdgeInsets.all(8.0)),
120-
GestureDetector(
121-
child: Text('Select from Gallery'),
122-
onTap: () {
123-
_openGallery();
124-
},
125-
),
141+
_imageAnswerFormat.useGallery
142+
? GestureDetector(
143+
child: Text('Select from Gallery'),
144+
onTap: () {
145+
_openGallery();
146+
},
147+
)
148+
: SizedBox(),
126149
],
127150
),
128151
),
@@ -132,6 +155,8 @@ class _ImageAnswerViewState extends State<ImageAnswerView> {
132155
}
133156

134157
Future<void> _openCamera() async {
158+
Container();
159+
135160
var picture = await ImagePicker().pickImage(
136161
source: ImageSource.camera,
137162
);

lib/src/views/widget/time_picker_widget.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import 'dart:async';
1111
import 'dart:math' as math;
12-
import 'dart:ui' as ui;
1312

1413
import 'package:flutter/material.dart';
1514
import 'package:flutter/rendering.dart';
@@ -1764,7 +1763,7 @@ class _HourMinuteTextFieldState extends State<_HourMinuteTextField> {
17641763
//
17651764
// resolved, remove the window check for semantics being enabled on web.
17661765
final String? hintText = MediaQuery.of(context).accessibleNavigation ||
1767-
ui.window.semanticsEnabled
1766+
WidgetsBinding.instance.platformDispatcher.semanticsEnabled
17681767
? widget.semanticHintText
17691768
: (focusNode.hasFocus ? null : _formattedValue);
17701769
inputDecoration = inputDecoration.copyWith(

0 commit comments

Comments
 (0)