提交 b768f8ee authored 作者: shixiaochen's avatar shixiaochen

1、增加FaceAuthUtils

上级 084ffc88
// This is a basic Flutter integration test.
//
// Since integration tests run in a full Flutter application, they can interact
// with the host side of a plugin implementation, unlike Dart unit tests.
//
// For more information about Flutter integration tests, please see
// https://docs.flutter.dev/cookbook/testing/integration/introduction
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:aliyun_face_plugin/aliyun_face_plugin.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('getPlatformVersion test', (WidgetTester tester) async {
final AliyunFacePlugin plugin = AliyunFacePlugin();
final String? version = await plugin.getPlatformVersion();
// The version string depends on the host platform running the test, so
// just assert that some non-empty string is returned.
expect(version?.isNotEmpty, true);
});
}
......@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:aliyun_face_plugin/aliyun_face_plugin.dart';
import 'package:aliyun_face_plugin/face_auth_plugins.dart';
void main() {
runApp(const MyApp());
......
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'aliyun_face_plugin_method_channel.dart';
abstract class AliyunFacePluginPlatform extends PlatformInterface {
......
library face_auth_plugins;
export 'package:aliyun_face_plugin/core/aliyun_face_plugin.dart';
\ No newline at end of file
import 'package:aliyun_face_plugin/face_auth_plugins.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
class FaceAuthUtils {
factory FaceAuthUtils() => _singleton;
static final FaceAuthUtils _singleton = FaceAuthUtils._();
FaceAuthUtils._() {
_faceAuthPlugin = AliyunFacePlugin();
}
static FaceAuthUtils get instance => _singleton;
static late AliyunFacePlugin _faceAuthPlugin;
/// 初始化刷脸认证
void initFaceAuth() {
_faceAuthPlugin.init();
}
/// 获取metaInfo
Future<String?> getMetaInfo() async {
String? metaInfo;
try {
// 获取客户端metaInfo,将信息发送到服务器端,调用服务器端相关接口获取认证ID,即CertifyId。
metaInfo = await _faceAuthPlugin.getMetaInfos();
debugPrint("FaceAuthUtils getMetaInfo: $metaInfo");
} on PlatformException {
debugPrint("FaceAuthUtils getMetaInfo: PlatformException");
}
return metaInfo;
}
/// 开始认证
Future<String?> startVerify({required String certifyId}) async {
String? verifyResult;
try {
// 调用认证接口,CertifyId需要调用服务器端接口获取。
// 每个CertifyId只能使用一次,否则会返回code: "2002(iOS), 1001(Android)"。
verifyResult = await _faceAuthPlugin.verify("certifyId", certifyId);
debugPrint("FaceAuthUtils startVerify: $verifyResult");
} on PlatformException {
debugPrint("FaceAuthUtils startVerify: PlatformException");
}
return verifyResult;
}
}
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:aliyun_face_plugin/aliyun_face_plugin_method_channel.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
MethodChannelAliyunFacePlugin platform = MethodChannelAliyunFacePlugin();
const MethodChannel channel = MethodChannel('aliyun_face_plugin');
setUp(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
channel,
(MethodCall methodCall) async {
return '42';
},
);
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(channel, null);
});
test('getPlatformVersion', () async {
expect(await platform.getPlatformVersion(), '42');
});
}
import 'package:flutter_test/flutter_test.dart';
import 'package:aliyun_face_plugin/aliyun_face_plugin.dart';
import 'package:aliyun_face_plugin/aliyun_face_plugin_platform_interface.dart';
import 'package:aliyun_face_plugin/aliyun_face_plugin_method_channel.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
class MockAliyunFacePluginPlatform
with MockPlatformInterfaceMixin
implements AliyunFacePluginPlatform {
@override
Future<String?> getPlatformVersion() => Future.value('42');
}
void main() {
final AliyunFacePluginPlatform initialPlatform = AliyunFacePluginPlatform.instance;
test('$MethodChannelAliyunFacePlugin is the default instance', () {
expect(initialPlatform, isInstanceOf<MethodChannelAliyunFacePlugin>());
});
test('getPlatformVersion', () async {
AliyunFacePlugin aliyunFacePlugin = AliyunFacePlugin();
MockAliyunFacePluginPlatform fakePlatform = MockAliyunFacePluginPlatform();
AliyunFacePluginPlatform.instance = fakePlatform;
expect(await aliyunFacePlugin.getPlatformVersion(), '42');
});
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论