face_plugin.dart 1.3 KB

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