简体   繁体   English

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

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

I'm new in flutter.我是颤振的新手。 I wanted to create an application with local biometrics I have used local auth and i need to have help with我想使用本地生物识别技术创建一个应用程序我使用了本地身份验证,我需要帮助

  1. close the application on the click of cancel button in local_auth,单击 local_auth 中的取消按钮关闭应用程序,
  2. close the application when maximum tries are done.完成最大尝试后关闭应用程序。
  3. pause the background untill authentication complete暂停后台直到身份验证完成

my code is我的代码是

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',
        ),
      ),
    );
  }
}

anyone please help me with this 3 queries..任何人请帮我解决这 3 个查询..

you can close the app with cancel click like this你可以像这样取消点击关闭应用程序

setState(() {
  if (isAuthorized) {
    _authorizedOrNot = "Authorized";
  } else {
    _authorizedOrNot = "Not Authorized";
    exit(0);
  }
});

just so you know exit(0) need to impot dart:io只是为了让您知道 exit(0) 需要导入 dart:io

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

相关问题 如何通过在 flutter 中单击外部来关闭覆盖 - how to close an overlay by clicking on outside in flutter Flutter 如何在 auth.signOut 之前取消 Streambuilder? - Flutter How to cancel Streambuilder before auth.signOut? 添加“ local_auth”库后,Flutter应用程序运行失败 - Flutter Application fails running after adding “local_auth” library Flutter - 初始化失败时以编程方式关闭应用程序 - Flutter - programmatically close application when init failed 单击另一张卡时如何关闭ExpansionTileCard - how to close ExpansionTileCard when clicking on another card 如何通过单击操作窗格中的按钮来关闭操作窗格 Flutter 可滑动 - How to close Action Pane By clicking button in action pane Flutter Slidable 如何在不点击 flutter 的情况下自动关闭对话框? - How to automatically close a dialog box without clicking in flutter? 检测 local_auth Flutter 何时发生生物特征变化 - Detect when there is a biometric change in local_auth Flutter 单击 flutter 应用程序中的按钮时,如何停止播放音乐应用程序 - How can i stop music apps from playing when clicking a button in my flutter application 单击本地推送通知时如何在 flutter 中导航和重新加载页面 - while clicking local push notification how to navigate and reload a page in flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM