face_plugin.dart 1.4 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. 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. print(value);
  20. if (value['event'] == 'initialize' && 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. _eventStream.listen((value) {
  41. if (value['event'] == 'startFaceLiveness') {
  42. data.call(value['data']);
  43. }
  44. }, onError: (error) {
  45. onFailed.call(error);
  46. });
  47. }
  48. }