简体   繁体   English

Flutter : local_auth: ^0.6.1 : PlatformException(error, You need to use a Theme.AppCompat theme (or后代) with this Activity., null)

[英]Flutter : local_auth: ^0.6.1 : PlatformException(error, You need to use a Theme.AppCompat theme (or descendant) with this activity., null)

I have problem integrated my app using package Local Auth , I already Follow documentation about configurated Packages to My App.我在使用包Local Auth集成我的应用程序时遇到问题,我已经按照有关配置包到我的应用程序的文档进行操作。 In the documentation it's said :在文档中它说:

Note that local_auth plugin requires the use of a FragmentActivity as opposed to Activity.请注意, local_auth插件需要使用 FragmentActivity 而不是 Activity。 This can be easily done by switching to use FlutterFragmentActivity as opposed to FlutterActivity in your manifest (or your own Activity class if you are extending the base class).这可以通过切换到在清单中使用 FlutterFragmentActivity 而不是 FlutterActivity 来轻松完成(如果您要扩展基类,则使用您自己的 Activity 类)。

But the problem show up after i edited MainActivity.kt :但是在我编辑MainActivity.kt后问题出现了:

package id.zeffry.debt_diary

import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant

import android.os.Build
import android.view.ViewTreeObserver
import android.view.WindowManager
class MainActivity: FlutterFragmentActivity() {
    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine);
    }
}

Log日志

I/flutter (22608): PlatformException(error, You need to use a Theme.AppCompat theme (or descendant) with this activity., null)

Source Code From Documentation :来自文档的源代码:

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:local_auth/local_auth.dart';

//? Testing Local Auth( Finger Print , Face Recognition, etc)
class TestingPage extends StatefulWidget {
  static const routeNamed = "/testing-page";

  @override
  _TestingPageState createState() => _TestingPageState();
}

class _TestingPageState extends State<TestingPage> {
  final LocalAuthentication auth = LocalAuthentication();

  bool _canCheckBiometrics;

  List<BiometricType> _availableBiometrics;

  String _authorized = 'Not Authorized';

  bool _isAuthenticating = false;

  Future<void> _checkBiometrics() async {
    bool canCheckBiometrics;
    try {
      canCheckBiometrics = await auth.canCheckBiometrics;
    } on PlatformException catch (e) {
      print(e);
    }
    if (!mounted) return;

    setState(() {
      _canCheckBiometrics = canCheckBiometrics;
    });
  }

  Future<void> _getAvailableBiometrics() async {
    List<BiometricType> availableBiometrics;
    try {
      availableBiometrics = await auth.getAvailableBiometrics();
    } on PlatformException catch (e) {
      print(e);
    }
    if (!mounted) return;

    setState(() {
      _availableBiometrics = availableBiometrics;
    });
  }

  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';
    setState(() {
      _authorized = message;
    });
  }

  void _cancelAuthentication() {
    auth.stopAuthentication();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ConstrainedBox(
        constraints: const BoxConstraints.expand(),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            Text('Can check biometrics: $_canCheckBiometrics\n'),
            RaisedButton(
              child: const Text('Check biometrics'),
              onPressed: _checkBiometrics,
            ),
            Text('Available biometrics: $_availableBiometrics\n'),
            RaisedButton(
              child: const Text('Get available biometrics'),
              onPressed: _getAvailableBiometrics,
            ),
            Text('Current State: $_authorized\n'),
            RaisedButton(
              child: Text(_isAuthenticating ? 'Cancel' : 'Authenticate'),
              onPressed:
                  _isAuthenticating ? _cancelAuthentication : _authenticate,
            )
          ],
        ),
      ),
    );
  }
}

Update Error From Real Device :来自真实设备的更新错误:

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
    at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:686)
    at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:649)
    at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:542)
    at androidx.appcompat.app.AppCompatDialog.setContentView(AppCompatDialog.java:95)
    at androidx.appcompat.app.AlertController.installContent(AlertController.java:232)
    at androidx.appcompat.app.AlertDialog.onCreate(AlertDialog.java:279)
    at android.app.Dialog.dispatchOnCreate(Dialog.java:389)
    at android.app.Dialog.show(Dialog.java:293)
    at androidx.fragment.app.DialogFragment.onStart(DialogFragment.java:486)
    at androidx.fragment.app.Fragment.performStart(Fragment.java:2627)
    at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:915)
    at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
    at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
    at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:439)
    at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2076)
    at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1866)
    at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1821)
    at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
    at androidx.fragment.app.FragmentManagerImpl.executePendingTransactions(FragmentManagerImpl.java:183)
    at androidx.biometric.BiometricPrompt.authenticateInternal(BiometricPrompt.java:749)
    at androidx.biometric.BiometricPrompt.authenticate(BiometricPrompt.java:658)
    at io.flutter.plugins.localauth.AuthenticationHelper$1.run(AuthenticationHelper.java:182)
    at android.os.Handler.handleCallback(Handler.java:754)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:165)
    at android.app.ActivityThread.main(ActivityThread.java:6375)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)

If you receive this error:如果您收到此错误:

Exception has occurred. PlatformException (PlatformException(error, You need to use a Theme.AppCompat theme (or descendant) with this activity., null))

Then you need to do this:然后你需要这样做:

  1. Go to android > app > src > main > res > values > style.xml转到android > app > src > main > res > values > style.xml

  2. Change the改变

<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">

to

<style name="LaunchTheme" parent="Theme.AppCompat.Light.NoActionBar">

For more information regarding setting MainActivity.kt in Kotlin;有关在 Kotlin 中设置MainActivity.kt更多信息; visit here: https://gist.github.com/akifarhan/f70a2c777651f2ea61a15eb92a5939c1访问这里: https : //gist.github.com/akifarhan/f70a2c777651f2ea61a15eb92a5939c1

Change改变

<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">

in android folder in file res/style.xml to在文件res/style.xml中的 android 文件夹中

<style name="LaunchTheme" parent="@android:style/Theme.AppCompat.Black.NoTitleBar">

Once you change the theme to AppCompat there is an issue with the view shown btw splash screen and first widget(which is usually same as you splash screen).将主题更改为 AppCompat 后,显示的视图会出现问题 btw 启动画面和第一个小部件(通常与启动画面相同)。 Now there is a small pop btw both images, which is super annoying and I had to remove this super feature and remain with same ugly logic as on iOS and see white screen btw splash theme and first widget :(现在有一个小的弹出 btw 两个图像,这非常烦人,我不得不删除这个超级功能并保持与 iOS 上相同的丑陋逻辑,并看到白屏 btw 启动主题和第一个小部件:(

 <meta-data
            android:name="io.flutter.embedding.android.SplashScreenDrawable"
            android:resource="@drawable/launch_background"
            />

暂无
暂无

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

相关问题 Flutter image_cropper 插件错误:“您需要在此活动中使用 Theme.AppCompat &gt; 主题(或后代)” - Flutter image_cropper plugin error: "You need to use a Theme.AppCompat > theme (or descendant) with this activity" java.lang.IllegalStateException:您需要在 Flutter App 中使用 Theme.AppCompat 主题(或后代)与此活动 - java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity in Flutter App flutter 中的 PlatformException(no_fragment_activity,local_auth 插件要求活动为 FragmentActivity。,null) - PlatformException(no_fragment_activity, local_auth plugin requires activity to be a FragmentActivity., null) in flutter 错误:PlatformException(no_fragment_activity,local_auth 插件要求活动是 FragmentActivity。,null) - Error: PlatformException(no_fragment_activity, local_auth plugin requires activity to be a FragmentActivity., null) 错误:使用生物特征验证时出错:PlatformException(no_fragment_activity,local_auth 插件要求活动是 FragmentActivity。,null,null) - Error: error using biometric auth: PlatformException(no_fragment_activity, local_auth plugin requires activity to be a FragmentActivity., null, null) 如何通过设置 theme.appcompat 解决 flutter 支付问题? - How to resolve flutter payment issue with setting theme.appcompat? Local_Auth FLUTTER PACKAGE - Local_Auth FLUTTER PACKAGE local_auth iOS(扑) - local_auth iOS (Flutter) Flutter local_auth 无法使用指纹的默认系统对话框 - Flutter local_auth unable to use default system dialog for fingerprint 在 Flutter 中配置 local_auth 插件 - configure local_auth plugin in flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM