繁体   English   中英

如何在本地身份验证中单击取消以及在颤振中超过最大尝试次数时关闭应用程序

[英]how to close the application on clicking cancel in local auth and also when maximum tries exceeds in flutter

我是颤振的新手。 我想使用本地生物识别技术创建一个应用程序我使用了本地身份验证,我需要帮助

  1. 单击 local_auth 中的取消按钮关闭应用程序,
  2. 完成最大尝试后关闭应用程序。
  3. 暂停后台直到身份验证完成

我的代码是

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM