【发布时间】:2021-12-26 10:01:27
【问题描述】:
我正在使用local_auth 进行用户验证。
我的应用的根小部件是 stateless 小部件。
错误: 像往常一样弹出身份验证屏幕。如果指纹(或密码)匹配,则用户可以访问该应用程序。但是,如果按下后退按钮(身份验证屏幕仍处于打开状态),身份验证窗口将消失,用户无需身份验证即可访问应用程序。
我正在使用Flutter-2.5.3 和local_auth-1.1.8。
这是main.dart:
//other imports here
import 'package:local_auth/local_auth.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
var localAuth = LocalAuthentication();
SharedPreferences prefs = await SharedPreferences.getInstance();
if (prefs.getBool('auth') == true) {
await localAuth.authenticate(
localizedReason: 'Authenticate to access Notes',
useErrorDialogs: true,
stickyAuth: true,);
}
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]).then((_) {
runApp(ProviderScope(child: MyApp()));
});
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
//returns my widget
}
}
我尝试在条件下移动runApp 块,这样只有在身份验证成功时才会调用主根窗口。然而结果还是一样。
这就是我所做的:
if (prefs.getBool('auth') == true) {
var authenticate = await localAuth.authenticate(
localizedReason: 'Authenticate to access Notes',
useErrorDialogs: true,
stickyAuth: true,);
if (authenticate == true) {
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]).then((_) {
runApp(ProviderScope(child: MyApp()));
});
}
}
【问题讨论】:
标签: android flutter dart flutter-dependencies