Step 2: Build the app
What you’ll do: create an empty Flutter app, add the CARP packages, and do the small Android and iPhone setup CARP needs.
You need:
- Flutter installed: Install Flutter.
When
flutter doctorshows green checkmarks for Android or iOS, you’re ready. - A phone set up for development: Android: turn on USB debugging, or iPhone: set up Xcode (iPhone apps can only be built on a Mac).
-
Create an empty Flutter app. In a terminal:
Terminal window flutter create my_first_carp_appcd my_first_carp_app -
Add the CARP packages.
Terminal window flutter pub add carp_core carp_mobile_sensing -
Do the platform setup.
In
android/app/src/main/AndroidManifest.xml, add this just above<application, so the app may count steps:android/app/src/main/AndroidManifest.xml <manifest xmlns:android="http://schemas.android.com/apk/res/android"><uses-permission android:name="android.permission.ACTIVITY_RECOGNITION"/><application ...></manifest>In
android/app/build.gradle.kts, add the two marked parts:android/app/build.gradle.kts android {compileOptions {isCoreLibraryDesugaringEnabled = true// ...leave the existing lines as they are}// ...}dependencies {coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.4")}Open
ios/Runner.xcworkspacein Xcode, select Runner → General, and set Minimum Deployments to 15.0. Then add this toios/Runner/Info.plistinside<dict>:ios/Runner/Info.plist <plist version="1.0"><dict>...<key>NSMotionUsageDescription</key><string>This app counts your steps for a research study.</string></dict></plist> -
Add your protocol. Create
lib/protocol.dartwith the code from Step 1:lib/protocol.dart import 'package:carp_core/carp_core.dart' hide Smartphone;import 'package:carp_mobile_sensing/carp_mobile_sensing.dart';SmartphoneStudyProtocol createProtocol() {final protocol = SmartphoneStudyProtocol(name: 'My first study',dataEndPoint: SQLiteDataEndPoint(),);final phone = Smartphone();protocol.addPrimaryDevice(phone);protocol.addParticipantRole(ParticipantRole('Participant'));protocol.addTaskControl(ImmediateTrigger(),BackgroundTask(name: 'Steps and battery', measures: [Measure(type: SensorSamplingPackage.STEP_EVENT),Measure(type: DeviceSamplingPackage.BATTERY_STATE),]),phone,);return protocol;}Smartphoneexists in both packages;hidetells Dart to use the one fromcarp_mobile_sensing.
Check it
Section titled “Check it”flutter runThe default Flutter counter app starts on your phone. CARP isn’t running yet; that’s the next step.
Next: Step 3: Deploy