Skip to content

Flutter

The Flutter plugin has been completely reworked in release 6.2, resulting in changes to the public interfaces. This section provides a side-by-side comparison of the basic features between releases 6.1 and 6.2.

Accessing FaceSDK

FaceSDK.
FaceSDK.instance.

var faceSdk = FaceSDK.instance;
faceSdk.

Initializing

var config = InitializationConfiguration();
config.license = base64Encode(licenseData.buffer.asUint8List());
var json = await FaceSDK.initializeWithConfig(config.toJson());
var response = jsonDecode(json);
if (!response["success"]) {
  print("Init failed: ");
  print(json);
} else {
  print("Init complete");
}
var (success, error) = await FaceSDK.instance.initialize(
  config: InitConfig(license),
);
if (success)
  print("Init complete");
else
  print("${error!.code}: ${error.message}");

Accessing Fields

var serviceUrl = await FaceSDK.getServiceUrl();
FaceSDK.setServiceUrl("new url");
var serviceUrl = FaceSDK.instance.serviceUrl;
FaceSDK.instance.serviceUrl = "new url";

Changing Configuration

var configuration = {};
var font = new Font();
font.name = "sans-serif";
font.size = 18;
var base64 = base64Encode((await rootBundle.load("image_accessories.png")).buffer.asUint8List());

configuration[CustomizationColor.ONBOARDING_SCREEN_START_BUTTON_TITLE] = 0xffffffff;
configuration[CustomizationFont.ONBOARDING_SCREEN_START_BUTTON] = font.toJson();
configuration[CustomizationImage.ONBOARDING_SCREEN_ACCESSORIES] = base64;

FaceSDK.setUiConfiguration(configuration);
FaceSDK.instance.customization.colors.onboardingScreenStartButtonTitle = Colors.white;
FaceSDK.instance.customization.fonts.onboardingScreenStartButton = Font("sans-serif", size: 18);
FaceSDK.instance.customization.images.onboardingScreenAccessories = await rootBundle.load("image_accessories.png");

Face Сapture

FaceSDK.presentFaceCaptureActivity().then((result) {
  var response = FaceCaptureResponse.fromJson(json.decode(result))!;
  var image = base64Decode(response.image!.bitmap!.replaceAll("\n", ""));
});
var response = await faceSdk.startFaceCapture();
var image = response.image;

Liveness

FaceSDK.startLiveness().then((value) {
  var result = LivenessResponse.fromJson(json.decode(value))!;
  var liveness = result.liveness;
});
var result = await faceSdk.startLiveness();
var liveness = result.liveness;

Match Faces

var request = new MatchFacesRequest();
request.images = [image1, image2];
FaceSDK.matchFaces(jsonEncode(request)).then((value) {
  var response = MatchFacesResponse.fromJson(json.decode(value));
  FaceSDK.matchFacesSimilarityThresholdSplit(jsonEncode(response!.results), 0.75).then((str) {
    var split = MatchFacesSimilarityThresholdSplit.fromJson(json.decode(str))!;
    if (split.matchedFaces.length > 0) {
      var similarity = split.matchedFaces[0]!.similarity!;
    }
  });
});
var request = MatchFacesRequest([image1, image2]);
var response = await faceSdk.matchFaces(request);
var split = await faceSdk.splitComparedFaces(response.results, 0.75);
if (split.matchedFaces.length > 0) {
  var similarity = split.matchedFaces[0].similarity;
}

Detect Faces

var configuration = new DetectFacesConfiguration();
configuration.onlyCentralFace = true;

var detectFacesRequest = new DetectFacesRequest();
detectFacesRequest.image = base64;
detectFacesRequest.configuration = configuration;

FaceSDK.detectFaces(jsonEncode(detectFacesRequest)).then((raw) {
  var detectFacesResponse = DetectFacesResponse.fromJson(jsonDecode(raw));
  var face = detectFacesResponse?.detection?.crop;
});
var config = DetectFacesConfig(onlyCentralFace: true);
var request = DetectFacesRequest(imageData, config);
var response = await FaceSDK.instance.detectFaces(request);
var face = response.detection?.crop;

Face Identification

var imageUpload = ImageUpload();
imageUpload.imageData = base64;

var searchPersonRequest = SearchPersonRequest();
searchPersonRequest.groupIdsForSearch = [];
searchPersonRequest.imageUpload = imageUpload;
searchPersonRequest.detectAll = true;

FaceSDK.searchPerson(searchPersonRequest.toJson()).then((str) {
  print(str);
});
var request = SearchPersonRequest(
  ImageUpload.withImageData(imageData),
  groupIdsForSearch: ["id1", "id2", "id3"],
  detectAll: true,
);

var (searchPerson, error) = await FaceSDK.instance.personDatabase.searchPerson(request);

Additional Resources