Installation
Add carp_survey_package to a CAMS app and configure Android and iOS.
The package runs on CARP Mobile Sensing (CAMS), so complete the CAMS setup in Installation first. Adding surveys on top of it takes four steps:
Add the packages
carp_survey_packagedoes not re-export the packages it builds on. Addresearch_packageto build your own surveys, andcognition_packageonly if you add cognitive tests.flutter pub addpicksresearch_package3.2.0, the newest version thatcarp_survey_packagesupports.Configure Android
research_package3.x depends on thehealthplugin, which requires API level 26 or later. RaiseminSdkinandroid/app/build.gradle.kts:android/app/build.gradle.kts Surveys and cognitive tests need no Android permissions. To ask for health data, for example in an informed consent flow, also set up Google Health Connect. See Android in the Health section.
Configure iOS
The
healthplugin also links HealthKit into the iOS app. Add the two HealthKit usage descriptions toios/Runner/Info.plist:ios/Runner/Info.plist To ask for health data, also add the HealthKit capability: without it, the authorization sheet does not appear. The minimum iOS version stays at 15.0, as for CAMS.
Warning
The
research_package4.0.0 release notes report that App Store review rejects apps that link HealthKit without using it. Version 4.0.0 drops thehealthdependency for this reason, butcarp_survey_package2.1.1 requires 3.x.cognition_packageplays its sounds withjust_audio. Its documentation says that App Store review then asks for a microphone usage description, because the audio session code includes a microphone API. AddNSMicrophoneUsageDescriptiontoInfo.plist, or, if the app does not record audio, compile the microphone code out:Swift Package Manager CocoaPods Clean the build, then set the environment variable for every build, including
flutter build ios:Add the macro to the
post_installblock of the Podfile. If the block already setsGCC_PREPROCESSOR_DEFINITIONS, for example forpermission_handler, add the macro to that list instead.ios/Podfile Register the sampling package
Register
SurveySamplingPackageinmain(), beforeconfigure():Call
CarpMobileSensing.ensureInitialized()beforeregister(): registering a sampling package before CAMS is initialized throws a null check error.Registering the package:
- adds the
dk.cachet.carp.surveymeasure type; - registers
RPAppTask,RPTaskResultDataand all Research Package and Cognition Package classes for JSON deserialization; - registers the user task factory that turns a triggered
survey,cognitionorinformed_consentapp task into aSurveyUserTask.
configure()restores the saved studies and survey tasks from JSON, which only works for registered types.- adds the
Add optional assets
Two Research Package features read files from fixed paths in your app's assets:
| Feature | Asset | Without the asset |
|---|---|---|
RPTimerStep(playSound: true) | assets/audio/RPTimerStepSound.mp3 | No sound plays. The package does not bundle the sound, and it only prints the error. |
RPLocalizations.delegate | assets/lang/<language_code>.json for every supported language | The delegate fails to load, because it does not catch a missing file. |
Declare the folders in pubspec.yaml:
The Research Package example app ships a timer sound, RPTimerStepSound.mp3. CPLocalizations.delegate needs no files in your app. For the translation files, see Translate the survey.
Troubleshooting
Change the research_package constraint in pubspec.yaml to ^3.2.0. carp_survey_package 2.1.1 and cognition_package 1.9.1 require ^3.0.0, so a constraint on 4.0.0 cannot resolve.
Hide Flutter's class in files that use the CARP TimeOfDay for a trigger:
Flutter's material.dart and carp_core both define a TimeOfDay class.
Set minSdk = 26 in android/app/build.gradle.kts. The health plugin requires API level 26, so the manifest merger rejects a lower value.
Register SurveySamplingPackage before you call SmartPhoneClientManager().configure(). Otherwise CAMS cannot read the RPAppTask JSON in the saved study and task queue, and the log shows Failed to load studies and Failed to load task queue, each with a SerializationException.
Next step
Quickstart
Build an app that schedules a daily WHO-5 survey.