Initialization
Before starting the video measurement, you’ll need to initialize the SDK.
Under the hood that step verifies the license and prepares the selected input pipeline. In the default camera modes this also connects to a platform camera device, so the app must have camera permissions before this step. If you initialize the mobile SDKs with cameraMode = CustomFrames, the SDK will not start a camera and you can provide frames from your own native pipeline instead.
You’ll need to provide an API key - see Authorization for more information.
Security tip: In production applications, short-lived tokens should be issued from a backend instead of embedding permanent API keys in client-side code. This reduces exposure of long-lived credentials while preserving standard SDK initialization flows for web and mobile applications.
import 'package:shenai_sdk/shenai_sdk.dart';
var API_KEY = ""
var USER_ID = ""
final _initResult = await ShenaiSdk.initialize(API_KEY, USER_ID);Error handling
You should check if the initialization was successful before proceeding further.
Possible errors at this stage include:
INVALID_API_KEY- the provided API key is malformed or inactiveCONNECTION_ERROR- there is a problem with network connection to the licensing serverINTERNAL_ERROR- other errors such as missing camera permissions
enum InitializationResult {
success,
failInvalidApiKey,
failConnectionError,
failInternalError
}
if (_initResult != InitializationResult.success) {
// handle error
}If the SDK has been successfully initialized, repeated calls to initialize will immediately return success - to start a new session first deinitialize the SDK.
Custom initialization options
The SDK can be configured at the initialization stage to determine its behavior and visual appearance. The options can also be changed at runtime.
Calibration Integration
To use calibration modes (CALIBRATION or CALIBRATED_MEASUREMENT), be sure to set
initializationMode. See the
Calibration page for more details.
Initialization Settings
If you’d like to change these initialization settings from the Shen.AI Portal instead of app code, see Remote Configuration.
enum Event {
startButtonClicked,
stopButtonClicked,
measurementFinished,
userFlowFinished,
screenChanged,
}
typedef EventCallback = void Function(Event event);
class InitializationSettings {
InitializationMode? initializationMode;
PrecisionMode? precisionMode;
OperatingMode? operatingMode;
MeasurementPreset? measurementPreset;
CameraMode? cameraMode;
OnboardingMode? onboardingMode;
bool? showUserInterface;
bool? showFacePositioningOverlay;
bool? showVisualWarnings;
bool? enableCameraSwap;
bool? showFaceMask;
bool? showBloodFlow;
bool? hideShenaiLogo;
bool? includeTimestampInPdf;
bool? enableStartAfterSuccess;
bool? enableSummaryScreen;
bool? showResultsFinishButton;
bool? enableHealthRisks;
bool? showHealthIndicesFinishButton;
bool? saveHealthRisksFactors;
bool? showOutOfRangeResultIndicators;
bool? showSignalQualityIndicator;
bool? showSignalTile;
bool? showStartStopButton;
bool? showInfoButton;
bool? showDisclaimer;
UiVersion? uiVersion;
bool? showTrialMetricLabels;
bool? applyPrecisionModeToBloodPressure;
List<MeasurementEnvironmentCondition>? blockingMeasurementConditions;
List<MeasurementEnvironmentCondition>? warningMeasurementConditions;
List<Screen>? uiFlowScreens;
int? frameWidth;
int? frameHeight;
int? rotation;
RisksFactors? risksFactors;
}
uiFlowScreens defines an explicit sequence of UI screens. If the list is non-empty it takes priority over per-screen
boolean flags such as showDisclaimer, enableSummaryScreen, and enableHealthRisks. Allowed screens: DISCLAIMER,
ONBOARDING, MEASUREMENT, RESULTS, HEALTH_RISKS_EDIT, HEALTH_RISKS.
See Configuration for detailed information on each option.
SDK events
SDK events notify your app about important changes in the SDK flow. They are most useful when you build a custom or partially custom UI and need to keep your app state aligned with the embedded SDK flow.
Available events:
START_BUTTON_CLICKED: the user clicked START in the SDK UI.STOP_BUTTON_CLICKED: the user clicked STOP in the SDK UI.MEASUREMENT_FINISHED: a measurement completed and results are ready to read.USER_FLOW_FINISHED: the user completed the current SDK flow.SCREEN_CHANGED: the SDK changed the currently displayed screen.
Platform access differs by SDK:
- Web, Android, and iOS expose
eventCallbackin initialization settings. - Flutter uses
ShenaiSdk.setEventCallback(...). - React Native emits the native
ShenAIEventevent. - Capacitor emits the
ShenAIEventplugin event. - MAUI exposes
ShenaiSdk.Events.
Use these events for app state, navigation, analytics, and custom UI updates. Keep event handlers lightweight and read detailed measurement data through the regular result APIs.
Providing the user interface
Unless you’re implementing a custom solution that doesn’t require a user interface, you’ll need to embed the SDK’s UI in your app. The SDK uses OpenGL/WebGL for rendering, embedded in a platform-specific native view component.
You can use the ShenaiView widget to embed the SDK’s UI in your Flutter app.
import 'package:shenai_sdk/shenai_view.dart';
...
@override
Widget build(BuildContext context) {
return Center(
child: ShenaiView(),
);
}Deinitialization
After finishing using the SDK you should deinitialize it - that will free up any allocated resources and disconnect from the camera.
ShenaiSdk.deinitialize();