Reputation: 5325
I'm beginner for the flutter, and I'm used local_auth: ^1.1.6
for my app fingerprint authentication . when I touch finger print icon but I got a flowing error.
I/flutter ( 805): PlatformException(no_fragment_activity, local_auth plugin requires activity to be a FragmentActivity., null, null)
my flutter version 2.2.1 / Dart Version .13.1
any one know some solution?
Thanks
here the my code
final LocalAuthentication _localAuthentication = LocalAuthentication();
String _message = "Not Authorized";
Future<bool> checkingForBioMetrics() async {
bool canCheckBiometrics = await _localAuthentication.canCheckBiometrics;
print(canCheckBiometrics);return canCheckBiometrics;
}
Future<void> _authenticateMe() async {
// 8. this method opens a dialog for fingerprint authentication.
// we do not need to create a dialog nut it popsup from device natively.
bool authenticated = false;
try {
authenticated = await
// ignore: deprecated_member_use
_localAuthentication.authenticateWithBiometrics(
localizedReason: "Authenticate for Testing",
// message for dialog
useErrorDialogs: true,
// show error in dialog
stickyAuth: true,
);
setState(() {_message = authenticated ? "Authorized" : "Not Authorized";
});
} catch (e) {
print(e);
}if (!mounted) return;
}
@override
void initState(){
checkingForBioMetrics();
super.initState();
}
TextEditingController _phoneController = new TextEditingController();
TextEditingController passwordController = new TextEditingController();
bool isSeen = true;
bool isSignIn = false;
check (BuildContext context){
if(_phoneController.text.length > 10 && passwordController.text.length > 5){
setState(() {
isSignIn = true;
});
}else{
isSignIn = false;
}
}
Container(
child: InkWell(
onTap: (){
_authenticateMe();
},
child: Container(
padding: EdgeInsets.only(right: 0,),
child: Image.asset("assets/icons/ic_finger_print.png",scale:7.1,),
),
),
),
Upvotes: 1
Views: 1264
Reputation: 787
First thing to do is to add the permission (you probably already did this):
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.[your.package]">
<uses-permission android:name="android.permission.USE_FINGERPRINT"/>
<application...
...
...
...
<manifest>
Then you need to change FlutterActivity
to FlutterFragmentActivity
:
package com.[your.package]
import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterFragmentActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterFragmentActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
If you happen to have Theme.AppCompat issues or 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:
Go to android>app>src>main>res>values>style.xml
.
Change this:
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
to
<style name="LaunchTheme" parent="Theme.AppCompat.Light.NoActionBar">
Upvotes: 3