I am using Firebase Auth for my app and for login and to handle errors I wrote it in a try-catch block, but when I enter an incorrect password the app just crashes and throws "PlatformException (PlatformException(ERROR_WRONG_PASSWORD, The password is invalid or the user does not have a password., null))" this error.
How can I fix this?
Here is the code, and the same is for registering users.
try {
final newUser = await _auth.signInWithEmailAndPassword(email: email, password: password);
if (newUser != null) {
Navigator.pop(context);
}
} catch (e) {
print(e);
}
If the solution with VSCode's "All Exceptions" didn't work for you...
Keep in mind that the debug version may throw exceptions while the same code in a release version may not.
If you are sure that your code is failing within the try block and you are handling the catch correctly (like OP is), then try running your app with flutter run --release and check to see if it works.
Check this question/answer here for a bit more information: Flutter catching all unhandled exceptions
Related
Hope someone has gone thru the same issue and can help me here:
I’m trying open a URL with the scheme itms-service using a AWS link with manifest.plist link using url_launcher library but I’m getting an error:
This is only on iOS app and the point of it is to be able to force update the app if it is on a lower version, this is currently only under an Enterprise certificate and not in the AppStore
Steps to Reproduce
final uri = Uri(path: 'itms-services://?action=download-manifest&url=https://awsservice.com/build/manifest.plist');
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
} else {
throw 'Could not launch $url';
}
Actual results (Errors):
\-canOpenURL: failed for URL: "itms-services://?action=download-manifest&url=https://awsservice.com/build/manifest.plist" - error: "Invalid input URL"
Failed to open URL itms-services%3A//%3Faction=download-manifest&url=https://awsservice.com/build/manifest.plist: Error Domain=NSOSStatusErrorDomain Code=-50 "invalid input parameters" UserInfo={NSDebugDescription=invalid input parameters, \_LSLine=249, \_LSFunction=-\[\_LSDOpenClient openURL:fileHandle:options:completionHandler:\]}
I’ve tried encoding the url string but nothing seems to work: Uri(path: Uri.encodeFull(url));
I've also tried adding itms-service as a UrlScheme. (but honestly this should be a default scheme for iOS)
Expected results:
Being able to open the link and download the app 🙏🏻
The answer was actually in the parsing of the stringL
Using Uri.parse is what solves it:
final uri = Uri.parse(url);
if (!await launchUrl(uri)) {
throw 'Could not launch $url';
}
I am using the API in Flutter.
Sometimes the server will return failed HTTP status codes and Flutter always auto-generated the alert message with shown the API URL in the console. I don't want to shown the API URL and this alert message makes the app look not complete from the user's perspective. I want to hide these alert messages. How to do that?
Example:
You can use the try/catch block.
try {
await http.get('...')
...
} catch(e) {
print(e);
}
'This is normal behavior for the browser' By https://github.com/flutter/flutter/issues/112155#issuecomment-1255310351
This is a way that can clear the console -> https://stackoverflow.com/a/73862039/17798537
I'm creating an app which should trigger a longer process in my nodejs server whereas the app should receive progress updates via socket.io.
The node server with socket.io works fine, I already tested it with a web client in the browser. However, I can't get the flutter code of the socket_io_client 1.0.2 package to execute in my flutter app.
This code is inside a method which is called once a user presses a button:
try {
print("step 1");
IO.Socket socket = IO.io('http://localhost:3000',
OptionBuilder().setTransports(['websocket']).build());
socket.on('connect', (_) {
print('connect: ${socket.id}');
socket.emit('process1', json.encode(_req));
});
socket.on('progress', (data) => print(data));
socket.onDisconnect((_) {
print('disconnect');
_finished = true;
});
} catch (e) {
print(e);
print("error");
}
print("step 2");
When clicking the button, the method executes, but not the socket part. In the console, I immediately get
step 1
step 2
but nothing else happens: The console logs the test statements immediately and the server never notices any incoming connections ... it is as the socket.io related code is just never executed. No errors, no console messages, nothing!
Does anyone have an idea why the codes behaves like this, why nothing happens?
Flutter (Channel stable, 2.10.4)
socket_io_client: ^1.0.2
I had the same problem with same versions of flutter and socket_io_client.
After changing the sockit_io_client to version ^2.0.0-beta.4-nullsafety.0 it was working.
https://pub.dev/packages/socket_io_client/versions/2.0.0-beta.4-nullsafety.0
There are many discussions about it on their github page. Will be fixed in the next releases.
I'm trying to get biometrics authentication to work again after updating the app I'm developing.
But I'm constantly getting the same error when activating it:
PlatformException(NotAvailable, Required security features not enabled, null, null)
The current one in the store has no problems at all.
I'm using local_auth: 1.1.4
MainActivity.java has been converted to a FragmentedActivity
I'm doing a simple check to see if the biometrics are available. Which they are
bool canCheckBiometrics = await auth.canCheckBiometrics;
List<BiometricType> availableBiometrics =
await auth.getAvailableBiometrics();
print(canCheckBiometrics); //Returns true
print(availableBiometrics.toString()); //Returns [BiometricType.fingerprint]
After that I try to do the authentication
try {
authenticated = await auth.authenticate(
biometricOnly: true,
localizedReason: 'Login with biometrics',
useErrorDialogs: true,
stickyAuth: false);
} on PlatformException catch (e) {
print(e);
}
This returns:
PlatformException(NotAvailable, Required security features not enabled, null, null)
And this is what the plugin comments in the code say.
// Indicates the device does not have a Touch ID/fingerprint scanner.
const String notAvailable = 'NotAvailable';
I'm not really sure what to check anymore. Is this something new I need to be aware of?
Really hope someone can help me with this issue!
Hope to hear!
I recommend that you verify all capabilities before of try authenticate the user.
Future<bool> authenticateIsAvailable() async {
final isAvailable = await localAuth.canCheckBiometrics;
final isDeviceSupported = await localAuth.isDeviceSupported();
return isAvailable && isDeviceSupported;
}
This way, you can call localAuth.authenticate only for phones that have credentials enrolled and probably don't have exceptions. Even though, catch the error if possible.
First of all, you need to add a biometric authentication method to your device from settings.
For example if you are using Pixel 2 API 32 as Android Emulator,
Go to Settings inside android emulator.
Go into Security
Under the Device Security section, select Pixel Imprint
Android will ask you to put your finger on the sensor, in this part you should click the Touch Sensor button from the Extended Emulator Settings of Android Studio.
After turning on fingerprint verification in this way, when you return to the application and try again, you will see that the error is gone.
Similarly, if you are trying with a real device or another emulator, you need to enable fingerprint authentication and try again.
I think you don't have a fingerprint activated yet, or you don't have permissions to use it, check the permissions and try again.
Check this out:
https://support.dashlane.com/hc/en-us/articles/203682911-How-to-set-biometric-authentication-or-a-PIN-code-to-unlock-Dashlane-on-Android
Go to settings -> security -> fingerprint and add fingerprint lock.
If you are using Android studio emulator then keep in mind that Android Studio emulator provides fake fingerprint scanning.
I had the same issue and after debugging I discovered that keyguardManager was always null and causing the plugin to throw not enable exception. I had to change the below method in LocalAuthPlugin as follows:
private boolean isDeviceSupported()
{
if (keyguardManager == null) return false;
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
keyguardManager.isDeviceSecure());
}
to
private boolean isDeviceSupported()
{
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M);
}
It worked for me, hopefully will work for you and others.
I try to build a Flutter app with Azure B2C authentication. To achive this I use the Flutter App Auth Plugin. At first sight everything seems to work as expected, but when I looked at the result the accesstoken is null. What am I missing? Obviously, I can get a connection to Azure and after entering the credentials a result is send back to my app. But why without token?
Debug session of the result:
Debug session of the result
My configuration:
configuration
I call the method like this:
Future<void> _login() async{
AuthorizationTokenResponse result;
try{
result = await _appauth.authorizeAndExchangeCode(
AuthorizationTokenRequest(_clientId, _redirectUrl,
discoveryUrl: _discoveryUrl,
scopes: _scopes),
);
}
catch(e){
print(e.toString());
}
if (result != null) {
_processAuthTokenResponse(result);
}
}
Does anybody know what I forgot?
Thanks!
You aren’t giving a scope to a resource so you don’t get an access token.
https://learn.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-access-tokens