Docs
Contact

Flutter SDK

Run the face video and voice checkups in your Flutter app: add the packages, set up Android and iOS, show a checkup.

The Flutter SDK runs YOU(th)'s checkups inside your Flutter app, on Android and iOS. It comes as one Dart package per checkup, each with a ready-made screen, or the parts to build your own: your app adds the packages of the checkups it runs, and carries nothing of the others.

PackageCheckups
youth_sdk_face_videoThe face video checkup on both models, which YOU(th) or your app picks between
youth_sdk_face_video_1The face video checkup on model 1 only
youth_sdk_face_video_2The face video checkup on model 2 only
youth_sdk_voiceThe two voice checkups, respiratory and mental fitness
youth_sdk_face_selfieThe selfie checkup
youth_sdk_body_compositionThe body composition checkup

These pages describe the SDK at 0.6.0, tagged v0.6.0.

What your app needs

  • A key, and checkups in an app switched on for your organization: tell your YOU(th) contact that you use the Flutter SDK. Keys says how keys work.
  • Access to the packages. They come from a private Git repository: your YOU(th) contact gives you its address and a read-only SSH key. Add it to your app says how to use the key.
  • Flutter 3.47.5 or later. With it, the face selfie's face detection (OpenCV) targets iOS 15, which Xcode 27 requires. From April 2027, App Store Connect takes only builds made with Xcode 27.
  • A real device. The checkups measure from a live camera and microphone, so they do not run on emulators or simulators.
  • A connection when the SDK starts and when a measurement starts, and for the whole of a voice or body composition checkup.
  • Portrait. The checkup screens are laid out for a phone held upright. Lock the screen to portrait while one shows, with SystemChrome.setPreferredOrientations, unless your whole app is portrait.
  • A plan for store review. Reviewers look closely at apps that run a checkup: see App Store and Google Play.
  • The wellness statement. The results are not for medical use: tell the person so.

Add it to your app

On every machine that builds your app, CI included, save the SSH key your YOU(th) contact gave you, for example as ~/.ssh/youth_sdk, keep it to yourself with chmod 600 ~/.ssh/youth_sdk, and give it a host name of its own in ~/.ssh/config:

Host github-youth  HostName github.com  User git  IdentityFile ~/.ssh/youth_sdk  IdentitiesOnly yes

The name matters: without it, SSH offers GitHub your own key first, and access is refused. Use it in the packages' address, as git@github-youth:…. Then add the packages of your checkups to pubspec.yaml, each from the same address and release, by its own path. For example, the face video checkup with the voice checkups:

dependencies:  youth_sdk_face_video:    git:      url: <the address your YOU(th) contact gives you>      ref: v0.6.0      path: packages/youth_sdk_face_video  youth_sdk_voice:    git:      url: <the address your YOU(th) contact gives you>      ref: v0.6.0      path: packages/youth_sdk_voice

Check the key with ssh -T git@github-youth: when it works, the answer names the SDK's repository and says that shell access is not provided. Then run flutter pub get. The packages share the SDK's core, which each brings with it, so they are released together: give every one the same ref, or flutter pub get refuses them. Don't list youth_sdk itself: the packages bring it. To upgrade, change ref everywhere and run it again. Adding a checkup later is adding its package.

The packages depend on sentry 9 or 10, and the face video packages on uuid 3 or 4: if your app uses either, take a version in that range. The SDK's error reports use a client of their own and leave your app's own error reporting untouched.

Android

  • Set minSdk to 28 or higher in android/app/build.gradle.kts (build.gradle in older projects). The SDK runs on Android 9 (API 28) or later, on 64-bit ARM devices (arm64-v8a).
  • The packages carry every library they use, so your build needs no account, key or registry of its own. Their other dependencies are public libraries from Google's Maven repository, Maven Central and JitPack, which the SDK declares for your build. If your app declares its repositories only in settings.gradle (dependencyResolutionManagement with FAIL_ON_PROJECT_REPOS), list those three there.
  • With face video model 2 (youth_sdk_face_video or youth_sdk_face_video_2) and Android Gradle Plugin 9, which new Flutter projects use, build every library of your app against Android 36, in android/build.gradle.kts, before the line project.evaluationDependsOn(":app"). Model 2's engine builds against Android 35, and under AGP 9 a library it uses asks for 36. Apps on AGP 8 don't need it:
subprojects {    afterEvaluate {        extensions.findByType(com.android.build.gradle.LibraryExtension::class.java)?.compileSdk = 36    }}
  • With the body composition package and Android Gradle Plugin 9, add android.uniquePackageNames=false to android/gradle.properties.
  • With the selfie package, every machine that builds your app needs CMake and Ninja, and on a Mac with Apple silicon, Rosetta: the selfie's face detection builds native code with them.
  • Declare the internet, the camera (face video, selfie, body composition) and the microphone (voice) in android/app/src/main/AndroidManifest.xml. A new Flutter app declares the internet only in its debug and profile builds, and some packages bring none of these lines: without the internet line, a release build with face video model 2, the selfie or voice cannot reach YOU(th).
<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.CAMERA" /><uses-permission android:name="android.permission.RECORD_AUDIO" />

Android permissions

The libraries inside the packages declare permissions of their own, which Android merges into your app's manifest. Each package adds these to what a new Flutter app declares:

PackagePermissions it adds
youth_sdk_face_video_1INTERNET, CAMERA, ACCESS_NETWORK_STATE and READ_PHONE_STATE, from model 1's library
youth_sdk_face_video_2None
youth_sdk_face_videoThose of youth_sdk_face_video_1
youth_sdk_voiceRECORD_AUDIO, from its recording library
youth_sdk_face_selfieCAMERA, RECORD_AUDIO, ACCESS_NETWORK_STATE and WRITE_EXTERNAL_STORAGE (up to Android 9), from its camera library, and READ_EXTERNAL_STORAGE, which Android's build adds beside the write permission
youth_sdk_body_compositionCAMERA; INTERNET, ACCESS_NETWORK_STATE, WAKE_LOCK, FOREGROUND_SERVICE and RECEIVE_BOOT_COMPLETED, from body composition's library and the Google libraries it uses

No package adds a Bluetooth or location permission on Android. The person is asked only for the camera and the microphone: your app asks for the camera (Ask for the camera), and a voice checkup asks for the microphone itself. Android grants the others when the app is installed, except READ_PHONE_STATE and the two storage permissions, which it grants only when an app asks for them, and nothing in the SDK does.

The packages also tell Google Play which devices can install your app: model 1 needs a camera and a front camera, model 2 needs OpenGL ES 3.1, and the microphone and camera permissions make Google Play expect a microphone and a camera.

To remove a permission your app doesn't want, mark it in your manifest with tools:node="remove", and check your merged manifest (build/app/outputs/logs/manifest-merger-release-report.txt in your app's build) after the next build:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools">  <uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove" /></manifest>

These are safe to remove:

  • READ_PHONE_STATE, with face video model 1. Nothing in the SDK or its libraries asks for it or reads the phone's state, so Android never grants it, and removing it takes nothing from a checkup.
  • RECORD_AUDIO, WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE, with the selfie, unless your app runs a voice checkup, which needs RECORD_AUDIO. The selfie opens the camera without sound and takes one photo, which its camera library keeps in your app's cache: that needs neither the microphone nor storage, and the camera library asks for the microphone only when sound is on.

Keep the rest. The camera, the microphone and the internet run the checkups, and the libraries declare the others for what they do: YOU(th) has not verified a checkup without them.

iOS

  • Set the deployment target to iOS 15.6 or later (platform :ios, '15.6' in ios/Podfile).
  • Say why your app uses the camera (face video, selfie, body composition), the microphone (voice) and Bluetooth (face video model 1), in ios/Runner/Info.plist. Without the microphone's line, iOS closes your app when a voice checkup starts recording. The Bluetooth line is needed because model 1's iOS framework links Apple's Bluetooth framework: without it, App Store Connect flags your upload (ITMS-90683). The SDK's own code does not use Bluetooth.
<key>NSCameraUsageDescription</key><string>The camera measures your heart rate and more from a short video of your face.</string><key>NSMicrophoneUsageDescription</key><string>The microphone records short voice samples for the voice checkups.</string><key>NSBluetoothAlwaysUsageDescription</key><string>This app doesn't use Bluetooth. Its face video checkup includes a component that supports Bluetooth devices.</string>

Start it

Start the SDK once, when your app starts, with your key. Import the library of each package you added: any one of them gives you YouthSdk and the rest of the SDK's core.

import 'package:youth_sdk_face_video/youth_sdk_face_video.dart';final state = await YouthSdk().init(apiKey: 'your test key');if (state != YouthInitState.success) {  // Show the person that the checkup is not available, and offer to try again.}

Show a checkup only once init has returned success. The reference lists what else init takes: the language, the biomarkers you want, and the error reports.

A key in your app suits test keys and prototypes. For an app in production, YOU(th) strongly recommends keeping the key on your backend.

Keep your key on your backend

Your key names your organization, but it is not a secret: anything shipped inside an app can be read from it. YOU(th) checks every checkup when it starts: that the key is active, that the checkup is on for it, and that its monthly limit is not reached. Test and live keys are separate, and your admins can revoke a key and issue a new one in the console, so a copied key cannot run past the limits set for it. Keys says more.

With initWithSessionProvider, the key stays on your backend and never ships in your app:

  1. Your app asks your backend for a session, sending the body YouthSdk().sessionRequest gives, for example {"delivery": "native", "platform": "ios", "sdk_version": "0.6.0"}.
  2. Your backend sends POST https://sdk.youth-platform.io/sdk/v1/sessions with that body and the headers X-Api-Key: <your key> and Content-Type: application/json. YOU(th) answers 201 with a session.
  3. Your backend returns the answer to your app unchanged, a refusal as well as a session, and your app gives it to the SDK.

In your app:

import 'dart:convert';import 'package:http/http.dart' as http;import 'package:youth_sdk_face_video/youth_sdk_face_video.dart';final state = await YouthSdk().initWithSessionProvider(() async {  final response = await http.post(    Uri.parse('https://api.example.com/youth-session'), // your backend    headers: {'Content-Type': 'application/json'},    body: jsonEncode(YouthSdk().sessionRequest),  );  // A session, or YOU(th)'s refusal, which the SDK reads. An answer of your backend's own  // (a user not signed in, say) is no session either.  final answer = jsonDecode(response.body);  if (answer is! Map<String, Object?>) throw Exception('No YOU(th) session');  return answer;});

On your backend, for example with Node.js:

// Read once at startup, so a missing key stops the server rather than every session.const youthSdkKey = process.env.YOUTH_SDK_KEY;if (!youthSdkKey) throw new Error("YOUTH_SDK_KEY is not set");app.post("/youth-session", requireSignedInUser, async (req, res) => {  const answer = await fetch("https://sdk.youth-platform.io/sdk/v1/sessions", {    method: "POST",    headers: { "X-Api-Key": youthSdkKey, "Content-Type": "application/json" },    body: JSON.stringify(req.body),  });  res    .status(answer.status)    .type("application/json")    .send(await answer.text());});
  • A new session each time. The SDK calls your provider when it starts, and again whenever a session's hour is over: return a new session each time, never a stored one.
  • Protect the endpoint as you protect the rest of your API, for example for signed-in users only. Open to anyone, it hands out sessions as freely as a key in the app.
  • When it fails, YOU(th)'s refusal of your key, handed on unchanged, makes failInvalidApiKey, as with init. A provider that throws, or gives nothing within 45 seconds, makes failConnectionError, and any other answer that is not a session failUnknown. locale, biomarkerScope and diagnostics work as with init.
  • Before production, use a live key of its own, with a monthly limit close to the checkups you expect, and if a key leaks, revoke it and issue a new one.

Ask for the camera

On Android and iOS, ask the person for the camera before you show the face video checkup: without it, the checkup ends with error 1005. For example, with the permission_handler plugin, which needs setup of its own in your iOS Podfile: its page says what.

import 'package:permission_handler/permission_handler.dart';Future<bool> ensureCameraPermission() async {  final status = await Permission.camera.request();  if (status.isPermanentlyDenied) {    await openAppSettings(); // let the person allow it in the settings  }  return status.isGranted;}

A voice checkup asks for the microphone itself the first time the person records, unless your app has asked already, and the body composition checkup asks for the camera itself.

Show the checkup

YouthVideoFrame is the whole checkup screen: the camera, the guidance, the record button and the progress. Give it the person and your callbacks:

YouthVideoFrame(  userInfo: const UserScanInformation(    age: 42,    gender: Gender.female,    height: 168, // centimetres    weight: 61.5, // kilograms    smokingState: SmokingState.nonSmoker,  ),  theme: const YouthVideoFrameTheme(),  onState: (state) {},  onFinalResults: (biomarkers) => showResults(biomarkers), // your results screen  onError: (error) => showError(error.message),)

Run your app on a phone, press record and hold still in even light for about a minute. Your showResults then gets one YouthDataPoint per biomarker, such as heart_rate at 64 bpm. Show them on your own screens rather than printing them: they are the person's health data, and a print can end up in device logs. Results says what they hold, and Flutter SDK examples shows whole lists and errors.

The measurement is better with the person's whole profile, and some biomarkers need it: the reference says what the person holds, and when to show a new checkup screen.

If the first run fails, check these:

  • init returns failInvalidApiKey until YOU(th) has switched on checkups in an app for your organization.
  • Error 2032 means the checkup is not on for your key, most often because no monthly limit is set yet. A face video model your key doesn't run, or whose package your app doesn't install, also ends with 2032.
  • Error 1005 means your app has not asked for the camera.

Choose the face video model

The face video checkup measures with a YOU(th) model. There are two, faceVideo1 and faceVideo2, and YOU(th) sets which of them your key may run, separately for your test and live keys. Name one with model, on YouthVideoFrame or YouthVideoController:

YouthVideoFrame(  userInfo: userInfo,  model: YouthFaceVideoModel.faceVideo1,  theme: const YouthVideoFrameTheme(),  onState: (_) {},  onFinalResults: (_) {},)
modelWhich model runs
Left outModel 1 when your key offers it and your app carries it, otherwise model 2
YouthFaceVideoModel.faceVideo1Model 1
YouthFaceVideoModel.faceVideo2Model 2
YouthFaceVideoModel.autoThe model the person's profile suits, among those your key offers: see the rules

The person's profile chooses the model only with auto. A model your key does not offer is refused before the camera starts, with error 2032, and so is a model whose package your app does not carry: youth_sdk_face_video carries both, youth_sdk_face_video_1 and youth_sdk_face_video_2 one each. auto chooses only among the models your key offers and your app carries. Model 2's library sends data of its own: Data and privacy says what.

Name a model when your product relies on a biomarker only one model returns, or when results must stay comparable across a person's measurements. Every result names the model and the version that produced it: see results.

Run a voice checkup

YouthVoiceFrame is the whole voice checkup screen: the guidance, a waveform and the record button. Give it the person, which checkup to run, and your callbacks:

YouthVoiceFrame(  type: VoiceScanType.mental, // respiratory when left out  user: const UserScanInformation(age: 42, gender: Gender.female),  theme: const YouthVideoFrameTheme(),  onFinalResults: (biomarkers) => save(biomarkers),  onError: (error) => showError(error.message),)
  • Respiratory. The person says a long "Aahh" for six seconds, twice, each time after tapping the record button. onFinalResults receives one biomarker, respiratory_symptoms_score.
  • Mental. The person taps the record button once and describes their day for 30 seconds. onFinalResults receives eight biomarkers: see Results.

Then the checkup uploads the recordings, checks that they are clear enough, and returns the results.

  • The person. A voice checkup uses their age and gender only. Give both: without an age, it counts the person as 35, and without a gender, as male.
  • Their voice leaves the device. The recordings are sent for analysis, with the person's year of birth and gender. Tell the person so before they record.
  • When it fails, onError says why, in a message for the person, and they record from the first sample again: see the reference.
  • A quiet room makes the recordings clear: no television, music or other voices, and nothing covering the microphone.

Closing the screen stops the voice checkup and releases the microphone.

Run a body composition checkup

The body composition checkup measures the person's body composition from a short video of their whole body, taken as they turn around in front of the camera. YouthBodyCompositionFrame shows the whole checkup: the camera, which guides the person into the frame and through the turn with spoken hints, then the upload and the wait for the analysis. A YouthBodyCompositionController drives it: create it when the screen opens and dispose it when it closes.

final controller = YouthBodyCompositionController(  consentAccepted: true, // once the person accepted your consent screen  user: const UserScanInformation(age: 42, gender: Gender.female, height: 168, weight: 61.5),  onFinalResults: (biomarkers) => save(biomarkers),  onError: (error) => showError(error.message),  onClose: () => Navigator.of(context).pop(),);YouthBodyCompositionFrame(controller: controller)

Then it makes the checkup, uploads the video, and waits for the analysis, which takes one to two minutes: onFinalResults receives six biomarkers, or those of them your biomarkerScope keeps: see Results.

  • The person. It needs every one of these: age (whole years, for a year of birth from 1900), gender (female or male), height (50 to 250 centimetres) and weight (20 to 500 kilograms). A profile that lacks one, says unspecified, or holds a value outside these ranges ends the checkup at once with userDataRequired, before the camera opens and before anything leaves the device. The analysis is told the year of birth, worked out from the age, not the age itself.
  • Consent first. Show your own consent screen before the checkup and pass consentAccepted: true only once the person accepted; with false the checkup ends at once with consentRequired. The SDK does not record the consent.
  • Their video leaves the device. The video and the profile are sent for analysis: tell the person so before they start. Data and privacy says what is sent.
  • When it fails, onError says why, in a message for the person, and the screen offers to send the video again or take a new one when that can help: see the reference.
  • The whole body must be in the frame, head to feet, and only one person in it, with the phone set down upright at waist height.

The checkup is counted once its video is uploaded, against a monthly limit of its own: ask your YOU(th) contact to set it. Until then your key does not offer the checkup, and it ends with checkupCreateFailed before the camera opens.

YOU(th)'s scores

Each checkup can also hand your app YOU(th)'s scores of its results: the scores every YOU(th) product shows, worked out by YOU(th)'s service for the person's age and sex. Your organization gets them always with the YOU(th) app; otherwise ask your YOU(th) contact. Give the checkup onFinalScores and onScoresError: YouthVideoFrame, YouthVoiceFrame, YouthFaceSelfieFrame and the four controllers take them.

YouthVideoFrame(  userInfo: const UserScanInformation(age: 42, gender: Gender.female),  theme: const YouthVideoFrameTheme(),  onState: (state) {},  onFinalResults: (biomarkers) => save(biomarkers),  onFinalScores: (scores) => showScores(scores),  onScoresError: (error) => showNoScores(error.code),)
  • The results come first, as without scores. Then onFinalScores gets the scores, or onScoresError says why there are none. The results stay valid either way.
  • The person needs an age from 18 to 120 and a gender of female or male. Without them, onScoresError gets profileIncomplete and nothing is asked: the SDK never assumes an age or a sex. The selfie's frame and controller take the person, user, for this alone.
  • No connection, no answer in time, or a refusal of YOU(th)'s service is scoresUnavailable.
  • Without scores for your organization, or without onFinalScores in your app, nothing is asked and neither callback is called.
  • After the screen closed. The scores can come once the checkup's screen is gone, as when your app moves to its results page in onFinalResults: check mounted before a setState.
  • One checkup after another. Each checkup's scores come after its own results, so a later checkup's results can come before an earlier one's scores. A checkup's results and scores go to the callbacks its screen had when it started.

The reference lists what the scores hold. A biomarker YOU(th) does not score, such as heart age, has none. YOU(th) keeps neither the scores nor the person's profile.

Build your own screen

To lay out the face video screen yourself, drive a YouthVideoController and show its camera with YouthVideoCameraView:

final controller = YouthVideoController(  user: const UserScanInformation(age: 42, gender: Gender.female),  onFinalResults: (biomarkers) => save(biomarkers),  onError: (error) => showError(error.code),);await controller.init();// In your screen:YouthVideoCameraView(controller: controller);// When the person is ready, and `controller.canStart` is true:await controller.start();// When the screen closes:controller.dispose();

state, warning, pulse and progress on the controller change as the measurement runs, for your own guidance and progress. A voice screen of your own drives a YouthVoiceController. The reference lists both: your own screen and your own voice screen.

Draw your own face guide

On face video model 1 the SDK draws a frame around the face: white while it is placed well, red while it isn't. Your organization's admins can switch it off in the YOU(th) console (Look and feel, then SDK), and your app draws its own from controller.face, laid over the camera view at the same size:

LayoutBuilder(  builder: (context, constraints) => Stack(    fit: StackFit.expand,    children: [      YouthVideoCameraView(controller: controller),      ValueListenableBuilder<YouthFace?>(        valueListenable: controller.face,        builder: (context, face, _) {          if (face == null) return const SizedBox.shrink();          return Positioned.fromRect(            rect: face.boxIn(constraints.biggest),            child: MyFaceGuide(isPlaced: face.isValid),          );        },      ),    ],  ),)

face is null while no face is in view, and always on model 2, which draws its own face mask. While the SDK's frame is off, the person sees only your guide: keep one on screen, or they lose the cue to place their face, and a measurement that ends without results still counts once it has started.

Make it yours

Every checkup takes a YouthVideoFrameTheme, which sets the footer's and the record button's colours and the style of each text: see the reference. What you leave out takes your organization's settings from the YOU(th) console, which also give the checkups their texts and their language, and can switch off the SDK's face guide so your app draws its own.

The ready-made screens, and YouthVideoCameraView, show "Powered by YOU(th)" themselves, so do not add your own.

Last updated