Skip to content

Commit

Permalink
This feature will add agreement view for the survey (#140)
Browse files Browse the repository at this point in the history
* 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

* Removed comment

* json file updated

* added default value for text question

* Boolean Answer defaultValue

* put back actual example_json.json

* Fixed consistent focus in non textfield views

There was a problem that keyboard was not hiding after navigating to
next question when the view is not text/double answer view

* added showCancelButton flag

* added fluter_markdown and url_launcher packge

* url_launcher

* added Agreement feature/view

* SingleCheckbox -> Agreement

* Fixed tapping text to set the agreement to true

* added result parsing for AgreementQuestionResult

* update build_runner dependency

* update flutter changes for android directory

* update flutter changes for ios directory

* update example pubspec.lock

* add missing JsonSerializable annotation for ImageQuestionResult

* re-run build_runner latest verson

* remove duplicate imports

* refactor: add flutter generated files

* refactor: update example_json with proper ids

* refactor: update styles for agreement answer view

* refactor: update pubspec.lock

* fix: remove duplicate ids for steps

* refactor: add toggling radio button state for agreement
  • Loading branch information
adar2378 committed Jan 18, 2024
1 parent 71d407b commit 0d5e4af
Show file tree
Hide file tree
Showing 22 changed files with 504 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.flutter.plugins.flutter_plugin_android_lifecycle.FlutterAndroidLifecyclePlugin;
import io.flutter.plugins.imagepicker.ImagePickerPlugin;
import dev.flutter.plugins.integration_test.IntegrationTestPlugin;
import io.flutter.plugins.urllauncher.UrlLauncherPlugin;
import io.flutter.plugins.videoplayer.VideoPlayerPlugin;

/**
Expand All @@ -19,6 +20,7 @@ public static void registerWith(PluginRegistry registry) {
FlutterAndroidLifecyclePlugin.registerWith(registry.registrarFor("io.flutter.plugins.flutter_plugin_android_lifecycle.FlutterAndroidLifecyclePlugin"));
ImagePickerPlugin.registerWith(registry.registrarFor("io.flutter.plugins.imagepicker.ImagePickerPlugin"));
IntegrationTestPlugin.registerWith(registry.registrarFor("dev.flutter.plugins.integration_test.IntegrationTestPlugin"));
UrlLauncherPlugin.registerWith(registry.registrarFor("io.flutter.plugins.urllauncher.UrlLauncherPlugin"));
VideoPlayerPlugin.registerWith(registry.registrarFor("io.flutter.plugins.videoplayer.VideoPlayerPlugin"));
}

Expand Down
4 changes: 2 additions & 2 deletions android/local.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sdk.dir=/Users/marvin/Library/Android/sdk
flutter.sdk=/Users/marvin/flutter
sdk.dir=/Users/saifulislam/Library/Android/sdk
flutter.sdk=/Users/saifulislam/Development/flutter_sdk/flutter
28 changes: 20 additions & 8 deletions example/assets/example_json.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"id": "1"
},
"destinationStepIdentifier": {
"id": "3"
"id": "14"
}
},
{
Expand Down Expand Up @@ -61,6 +61,21 @@
"text": "Get ready for a bunch of super random questions!",
"buttonText": "Let's go!"
},
{
"stepIdentifier": {
"id": "14"
},
"type": "question",
"isOptional": true,
"title": "Before we begin",
"text": "In order to provide our services, this app will collect and use your sensitive health data based on your consent.",
"answerFormat": {
"type": "agreement",
"defaultValue": "NEGATIVE",
"markdownDescription": "Please read our [Privacy Notice](https://www.healthylongevity.cafe/privacy) carefully to ensure that you understand it fully.",
"markdownAgreementText": "By clicking this option you consent to the collection and processing of your personal data according to our [Privacy Notice](https://www.healthylongevity.cafe/privacy)"
}
},
{
"stepIdentifier": {
"id": "2"
Expand Down Expand Up @@ -199,8 +214,7 @@
"answerFormat": {
"type": "multiple",
"otherField": true,
"textChoices": [
{
"textChoices": [{
"text": "Penicillin",
"value": "Penicillin"
},
Expand Down Expand Up @@ -228,8 +242,7 @@
"answerFormat": {
"type": "multiple_auto_complete",
"otherField": true,
"textChoices": [
{
"textChoices": [{
"text": "Penicillin",
"value": "Penicillin"
},
Expand All @@ -238,8 +251,7 @@
"value": "Latex"
}
],
"suggestions": [
{
"suggestions": [{
"text": "Pet",
"value": "Pet"
},
Expand Down Expand Up @@ -303,4 +315,4 @@
}
}
]
}
}
8 changes: 7 additions & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ PODS:
- Flutter
- integration_test (0.0.1):
- Flutter
- url_launcher_ios (0.0.1):
- Flutter
- video_player_avfoundation (0.0.1):
- Flutter
- FlutterMacOS
Expand All @@ -15,6 +17,7 @@ DEPENDENCIES:
- Flutter (from `Flutter`)
- image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`)
- integration_test (from `.symlinks/plugins/integration_test/ios`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
- video_player_avfoundation (from `.symlinks/plugins/video_player_avfoundation/darwin`)

EXTERNAL SOURCES:
Expand All @@ -26,6 +29,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/image_picker_ios/ios"
integration_test:
:path: ".symlinks/plugins/integration_test/ios"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"
video_player_avfoundation:
:path: ".symlinks/plugins/video_player_avfoundation/darwin"

Expand All @@ -34,8 +39,9 @@ SPEC CHECKSUMS:
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
image_picker_ios: 4a8aadfbb6dc30ad5141a2ce3832af9214a705b5
integration_test: 13825b8a9334a850581300559b8839134b124670
url_launcher_ios: bf5ce03e0e2088bad9cc378ea97fa0ed5b49673b
video_player_avfoundation: e9e6f9cae7d7a6d9b43519b0aab382bca60fcfd1

PODFILE CHECKSUM: 70d9d25280d0dd177a5f637cdb0f0b0b12c6a189

COCOAPODS: 1.14.3
COCOAPODS: 1.13.0
16 changes: 12 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ class _MyAppState extends State<MyApp> {
fontSize: 18.0,
color: Colors.black,
),
bodySmall: TextStyle(
fontSize: 14.0,
color: Colors.black,
),
titleMedium: TextStyle(
fontSize: 18.0,
color: Colors.black,
Expand Down Expand Up @@ -284,10 +288,14 @@ class _MyAppState extends State<MyApp> {
}

Future<Task> getJsonTask() async {
final String taskJson =
await rootBundle.loadString('assets/example_json.json');
final Map<String, dynamic> taskMap = json.decode(taskJson);
try {
final String taskJson =
await rootBundle.loadString('assets/example_json.json');
final Map<String, dynamic> taskMap = json.decode(taskJson);

return Task.fromJson(taskMap);
return Task.fromJson(taskMap);
} catch (e) {
rethrow;
}
}
}
4 changes: 4 additions & 0 deletions example/linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
#include "generated_plugin_registrant.h"

#include <file_selector_linux/file_selector_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
}
1 change: 1 addition & 0 deletions example/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux
url_launcher_linux
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
2 changes: 2 additions & 0 deletions example/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import FlutterMacOS
import Foundation

import file_selector_macos
import url_launcher_macos
import video_player_avfoundation

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
FVPVideoPlayerPlugin.register(with: registry.registrar(forPlugin: "FVPVideoPlayerPlugin"))
}
90 changes: 89 additions & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.4.9"
args:
dependency: transitive
description:
name: args
sha256: eef6c46b622e0494a36c5a12d10d77fb4e855501a91c1b9ef9339326e58f0596
url: "https://pub.dev"
source: hosted
version: "2.4.2"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -211,6 +219,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_markdown:
dependency: transitive
description:
name: flutter_markdown
sha256: "35108526a233cc0755664d445f8a6b4b61e6f8fe993b3658b80b4a26827fc196"
url: "https://pub.dev"
source: hosted
version: "0.6.18+2"
flutter_platform_widgets:
dependency: transitive
description:
Expand Down Expand Up @@ -383,6 +399,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.7.0"
markdown:
dependency: transitive
description:
name: markdown
sha256: acf35edccc0463a9d7384e437c015a3535772e09714cf60e07eeef3a15870dcd
url: "https://pub.dev"
source: hosted
version: "7.1.1"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -538,7 +562,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.1.2"
version: "0.2.0"
sync_http:
dependency: transitive
description:
Expand Down Expand Up @@ -571,6 +595,70 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.2"
url_launcher:
dependency: transitive
description:
name: url_launcher
sha256: e9aa5ea75c84cf46b3db4eea212523591211c3cf2e13099ee4ec147f54201c86
url: "https://pub.dev"
source: hosted
version: "6.2.2"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
sha256: "31222ffb0063171b526d3e569079cf1f8b294075ba323443fdc690842bfd4def"
url: "https://pub.dev"
source: hosted
version: "6.2.0"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
sha256: bba3373219b7abb6b5e0d071b0fe66dfbe005d07517a68e38d4fc3638f35c6d3
url: "https://pub.dev"
source: hosted
version: "6.2.1"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
sha256: ab360eb661f8879369acac07b6bb3ff09d9471155357da8443fd5d3cf7363811
url: "https://pub.dev"
source: hosted
version: "3.1.1"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
sha256: b7244901ea3cf489c5335bdacda07264a6e960b1c1b1a9f91e4bc371d9e68234
url: "https://pub.dev"
source: hosted
version: "3.1.0"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
sha256: "980e8d9af422f477be6948bdfb68df8433be71f5743a188968b0c1b887807e50"
url: "https://pub.dev"
source: hosted
version: "2.2.0"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
sha256: "7286aec002c8feecc338cc33269e96b73955ab227456e9fb2a91f7fab8a358e9"
url: "https://pub.dev"
source: hosted
version: "2.2.2"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
sha256: ecf9725510600aa2bb6d7ddabe16357691b6d2805f66216a97d1b881e21beff7
url: "https://pub.dev"
source: hosted
version: "3.1.1"
uuid:
dependency: transitive
description:
Expand Down
3 changes: 3 additions & 0 deletions example/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
#include "generated_plugin_registrant.h"

#include <file_selector_windows/file_selector_windows.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
1 change: 1 addition & 0 deletions example/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

list(APPEND FLUTTER_PLUGIN_LIST
file_selector_windows
url_launcher_windows
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
7 changes: 7 additions & 0 deletions ios/Runner/GeneratedPluginRegistrant.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
@import integration_test;
#endif

#if __has_include(<url_launcher_ios/URLLauncherPlugin.h>)
#import <url_launcher_ios/URLLauncherPlugin.h>
#else
@import url_launcher_ios;
#endif

#if __has_include(<video_player_avfoundation/FVPVideoPlayerPlugin.h>)
#import <video_player_avfoundation/FVPVideoPlayerPlugin.h>
#else
Expand All @@ -36,6 +42,7 @@ + (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
[CameraPlugin registerWithRegistrar:[registry registrarForPlugin:@"CameraPlugin"]];
[FLTImagePickerPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTImagePickerPlugin"]];
[IntegrationTestPlugin registerWithRegistrar:[registry registrarForPlugin:@"IntegrationTestPlugin"]];
[URLLauncherPlugin registerWithRegistrar:[registry registrarForPlugin:@"URLLauncherPlugin"]];
[FVPVideoPlayerPlugin registerWithRegistrar:[registry registrarForPlugin:@"FVPVideoPlayerPlugin"]];
}

Expand Down
24 changes: 24 additions & 0 deletions lib/src/answer_format/agreement_answer_format.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:json_annotation/json_annotation.dart';
import 'package:survey_kit/src/answer_format/answer_format.dart';
import 'package:survey_kit/src/answer_format/boolean_answer_format.dart';

part 'agreement_answer_format.g.dart';

@JsonSerializable()
class AgreementAnswerFormat implements AnswerFormat {
final BooleanResult result;
final BooleanResult? defaultValue;
final String? markdownDescription;
final String? markdownAgreementText;

const AgreementAnswerFormat({
this.result = BooleanResult.NEGATIVE,
this.defaultValue,
this.markdownDescription,
this.markdownAgreementText,
}) : super();

factory AgreementAnswerFormat.fromJson(Map<String, dynamic> json) =>
_$AgreementAnswerFormatFromJson(json);
Map<String, dynamic> toJson() => _$AgreementAnswerFormatToJson(this);
}
Loading

0 comments on commit 0d5e4af

Please sign in to comment.