问题描述
我是新手。我想创建一个使用本地生物特征识别的应用程序,并且需要帮助
我的代码是
import 'dart:async';
import 'package:LogInSignIn.dart';
import 'package:Flutter/material.dart';
import 'package:cashhub/homescreen.dart';
import 'package:local_auth/local_auth.dart';
import 'package:Flutter/services.dart';
void main() {
setupLocator();
runApp(new MaterialApp(
debugShowCheckedModeBanner: false,home: new SplashScreen(),routes: <String,WidgetBuilder>{
'/HomeScreen': (BuildContext context) => new LogInSignIn(),},));
}
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => new _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
//final LocalAuthenticationService _localAuth = locator<LocalAuthenticationService>();
final LocalAuthentication auth = LocalAuthentication();
bool _canCheckBiometrics;
List<BiometricType> _availableBiometrics;
String _authorized = 'Not Authorized';
bool _isAuthenticating = false;
startTime() async {
var _duration = new Duration(seconds: 4);
return new Timer(_duration,navigationPage);
}
Future<void> _authenticate() async {
bool authenticated = false;
try {
setState(() {
_isAuthenticating = true;
_authorized = 'Authenticating';
});
authenticated = await auth.authenticateWithBiometrics(
localizedReason: 'Scan your fingerprint to authenticate',useErrorDialogs: true,stickyAuth: true);
setState(() {
_isAuthenticating = false;
_authorized = 'Authenticating';
});
} on PlatformException catch (e) {
print(e);
}
if (!mounted) return;
final String message = authenticated ? 'Authorized' : 'Not Authorized';
// if( message == "Not Authorized"){
// SystemNavigator.pop();
// }
setState(() {
_authorized = message;
});
}
void navigationPage() {
Navigator.of(context).pushReplacementNamed('/HomeScreen');
}
@override
void initState() {
_authenticate();
//autho();
super.initState();
startTime();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(
child: new Image.asset('assets/splashlogo.png',),);
}
}
有人请帮我解决这3个问题。
解决方法
你可以像这样取消点击关闭应用
setState(() {
if (isAuthorized) {
_authorizedOrNot = "Authorized";
} else {
_authorizedOrNot = "Not Authorized";
exit(0);
}
});
只是为了让您知道 exit(0) 需要导入 dart:io