face_plugin.dart 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import 'package:flutter/services.dart';
  2. import 'face_config.dart';
  3. class FacePlugin {
  4. MethodChannel _channel = MethodChannel("plugin.bughub.dev/fltbdface");
  5. initialize(
  6. {String licenseId,
  7. String licenseFileName,
  8. Function onSuccess,
  9. Function onFailed}) {
  10. _channel.invokeMethod("initialize", {
  11. "licenseId": licenseId,
  12. "licenseFileName": licenseFileName
  13. }).catchError((error) {
  14. print("initialize:$error");
  15. });
  16. EventChannel("plugin.bughub.dev/event:init")
  17. .receiveBroadcastStream()
  18. .listen((value) {
  19. print(value);
  20. if (value['status'] == 0) {
  21. onSuccess?.call();
  22. }
  23. }, onError: (error) {
  24. onFailed?.call(error);
  25. });
  26. return this;
  27. }
  28. setFaceConfig(FaceConfig _config) {
  29. _channel
  30. .invokeMethod("setFaceConfig", _config.toJson())
  31. .catchError((error) {
  32. print("setFaceConfig:$error");
  33. });
  34. }
  35. startFaceLiveness({Function data, Function onFailed}) {
  36. _channel.invokeMethod("startFaceLiveness").catchError((error) {
  37. print("startFaceLiveness:$error");
  38. onFailed.call(error);
  39. });
  40. EventChannel("plugin.bughub.dev/event").receiveBroadcastStream().listen(
  41. (value) {
  42. data.call(value);
  43. }, onError: (error) {
  44. onFailed.call(error);
  45. });
  46. }
  47. }