I have faced this issue recently. The local authentication would work flawlessly on flutter run and --release, --profile . But when I make the APK and then install it, the local auth does not work, the app crashes. There is no error in the app when i run the same app but when the cable is connected to my computer.
Here, the function call begins,
onPressed: () {
bool enable = preferences.getBool('bioAuth');
if (enable == null || enable == false) {
showSnack('Biometric Auth not Enabled...');
} else {
biometricLogin(
context: context, mainCol: mainCol);
}
},
Here is the biometricLogin Function.
void biometricLogin({context, mainCol}) async {
bool authenticated =
await checkBiometric(context: context, mainCol: mainCol);
if (authenticated == null || authenticated == false) {
showSnack('BioAuth not valid...');
} else {
bool isGoogle = preferences.getBool('googleSignIn');
bool isApple = preferences.getBool('appleSignin');
if (isGoogle) {
showSnack('Logging in...');
User user = await _auth.signInWIthGoogleCreds();
print(user);
if (user == null) {
showSnack('Try logging in through Google again...');
}
} else if (isApple) {
showSnack('Logging in...');
User user = await _auth.signInWIthAppleCreds();
print(user);
if (user == null) {
showSnack('Try logging in through Apple again...');
}
} else {
User user;
showSnack('Logging in...');
var email = preferences.getString('email');
var password = preferences.getString('pass');
user = await _auth.signIn(email, password);
if (user != null) {
await preferences.setBool('loggedIn', true);
} else {
showSnack('Something went wrong');
}
}
}
}
And here is checkBiometrics function .
Future<bool> checkBiometric({context, mainCol}) async {
if (bioAuth == null || bioAuth == false) {
showSnack('Biometrics not Enabled');
return false;
} else {
try {
canCheckBiometrics = await auth.canCheckBiometrics;
if (!mounted) return false;
List<BiometricType> availableBiometrics;
availableBiometrics = await auth.getAvailableBiometrics();
bool authenticated = false;
if (Platform.isIOS) {
const iosStrings = const IOSAuthMessages(
cancelButton: 'cancel',
goToSettingsButton: 'settings',
goToSettingsDescription: 'Please set up your Touch ID.',
lockOut: 'Please re-enable your Touch ID');
if (availableBiometrics.contains(BiometricType.face) ||
availableBiometrics.contains(BiometricType.fingerprint)) {
authenticated = await auth.authenticateWithBiometrics(
localizedReason: "Please authenticate to login",
useErrorDialogs: true,
iOSAuthStrings: iosStrings,
stickyAuth: true,
);
} else
authenticated = false;
} else {
authenticated = await auth.authenticateWithBiometrics(
localizedReason: 'Touch your finger on the sensor to login',
useErrorDialogs: true,
stickyAuth: true,
);
}
return authenticated;
} catch (e) {
showSnack("error using biometric auth: $e");
}
setState(() {
authenticated = authenticated ? true : false;
});
return authenticated;
}
}
As far as I understand. The app doesnot goes ahead of checkBiometrics, because it crashes just by pressing the button.