首页 > 解决方案 > 限制用户进行特定类型的生物特征认证?

问题描述

嘿, 我想开发一个应用程序,其中用户首先被限制进行指纹认证,指纹认证后,用户将被限制为面部识别认证。但是当我使用 Local_auth.authenticate 时,它​​为用户提供了想要扫描指纹或面部 ID 的选项,我该如何解决这个问题。

标签: androidflutterandroid-studiolocalauthentication

解决方案


你可以试试下面的代码:

Future<void> _authenticateMe() async {
// 8. this method opens a dialog for fingerprint authentication.
//    we do not need to create a dialog nut it popsup from device natively.
bool authenticated = false;
try {
  authenticated = await _localAuthentication.authenticateWithBiometrics(
    localizedReason: "Authenticate for Testing", // message for dialog
    useErrorDialogs: true,// show error in dialog
    stickyAuth: true,// native process

  );
  print('support device try: '+authenticated.toString());
} catch (e) {
  print('support device catch: '+e.toString());
  print(e);
}
if (!mounted) return;
setState(() {
  _authorizedOrNot = authenticated ? "Authorized" : "Not Authorized";
});

if(_authorizedOrNot == 'Authorized'){
  Navigator.of(context).push(MaterialPageRoute(builder: (context) => HomeScreen()));
}

}


推荐阅读