簡體   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