Initialization

Initialization

Before starting the video measurement, you'll need to initialize the SDK.

Under the hood that step verifies the license and connects to a native platform camera device. The app must have camera permissions before this step.

You'll need to provide an API key - see Authorization for more information.

lib/main.dart
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 inactive
  • CONNECTION_ERROR - there is a problem with network connection to the licensing server
  • INTERNAL_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 it's behavior and visual appearance. The options can also be changed at runtime.

class InitializationSettings {
  PrecisionMode precisionMode;
  OperatingMode operatingMode;
  MeasurementPreset measurementPreset;
  CameraMode cameraMode;
  OnboardingMode onboardingMode;
  bool? showUserInterface;
  bool? showFacePositioningOverlay;
  bool? showVisualWarnings;
  bool? enableCameraSwap;
  bool? showFaceMask;
  bool? showBloodFlow;
  bool? hideShenaiLogo;
}

See Configuration for detailed information on each option.

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.

lib/main.dart
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();