Solvedflutterfire [<Firebase_Auth>] Unhandled Platform Exception Before Able to Catch SignInWithEmailAndPassword FirebaseAuthException

#3341 Relates to this.

Bug Description

I have just upgraded to the new FlutterFire library and am experiencing the above with the new version of firebase_auth (0.18.0+1), which did not occur in the previous version I used (0.16.1).

Here is a code snippet of my email/password authentication method.

auth.User _user;
          try {
            _user = (await _firebaseAuth.signInWithEmailAndPassword(
              email: email,
              password: password,
          } on auth.FirebaseAuthException catch (e) {
            printMessage("FirebaseAuthException code: ${e.code}",
                isErrorMessage: true);
            _user = null;
          } on Exception catch (e) {
            printMessage("Exception code: ${e.toString()}",
                isErrorMessage: true);
            _user = null;

The problem is that a platform exception is being triggered immediately after the call to signInWithEmailAndPassword and before the on auth.FirebaseAuthException catch (e) { block. The exception stops the code (unless I uncheck breakpoints, unhandled exceptions in my VSCode debugger - I see from the issue referenced above that it worked in Android Studio but it is not clear if AS was set to trap unhandled errors. I don't know AS that well.)

The exception occurs at line 572 in C:\flutter\packages\flutter\lib\src\services\message_codecs.dart

if (errorCode is String && (errorMessage == null || errorMessage is String) && !buffer.hasRemaining)
line 572 =>      throw PlatformException(code: errorCode, message: errorMessage as String, details: errorDetails);
      throw const FormatException('Invalid envelope');

The error message thrown is:

Exception has occurred.
PlatformException (PlatformException(firebase_auth, There is no
user record corresponding to this identifier. The user may have been deleted., {code: user-not-found, additionalData: {},
message: There is no user record corresponding to this identifier. The user may have been deleted.}))

This is called from line 361 in C:\flutter\packages\flutter\lib\src\services\platform_channel.dart

Future<Map<K, V>> invokeMapMethod<K, V>(String method, [ dynamic arguments ]) async {
line 361=>    final Map<dynamic, dynamic> result = await invokeMethod<Map<dynamic, dynamic>>(method, arguments);
    return result?.cast<K, V>();

If I continue the code run then the FirebaseAuthException block processes the firebase exception correctly. Similarly, if I turn off the unhandled exceptions check, the platform error is not seen and the FirebaseAuthException block shows the correct error message.

Steps to Reproduce

Simply enter an non-existant or badly formatted email address, or an invalid password to an existing address as the parameters to the signInWithEmailAndPassword method and the platform error will occur.

Expected behavior

I would expect the platform error not to occur or to propagate the error correctly ie. to be handled.

Flutter doctor

flutter doctor -v
[√] Flutter (Channel stable, 1.20.2, on Microsoft Windows [Version 10.0.20206.1000], locale en-ZA)
• Flutter version 1.20.2 at C:\flutter
• Framework revision bbfbf1770c (3 weeks ago), 2020-08-13 08:33:09 -0700
• Engine revision 9d5b21729f
• Dart version 2.9.1

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
• Android SDK at D:\Android\Sdk
• Platform android-30, build-tools 29.0.0
• ANDROID_HOME = D:\Android\Sdk
• Java binary at: C:\Program Files\Android\Android Studio1\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)
• All Android licenses accepted.

[√] Android Studio (version 3.5)
• Android Studio at C:\Program Files\Android\Android Studio1
• Flutter plugin version 43.0.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b03)

[√] VS Code (version 1.48.2)
• VS Code at C:\Users\dicki\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.14.0

[√] Connected device (1 available)
• AOSP on IA Emulator (mobile) • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)

• No issues found!

41 Answers

✔️Accepted Answer

I am able to replicate this issue on latest stable (1.20.3) while debugging signInWithEmailAndPassword() method from firebase_auth's official example in Android Studio on Android device 8.1.0.

Screen Shot 2020-09-09 at 3 22 36 PM
Screen Shot 2020-09-09 at 3 23 16 PM

Steps to replicate:

  1. Run firebase_auth official example plugin.
  2. Tap on Test SignIn/SignOut.
  3. Put debugger on void _signInWithEmailAndPassword() method and run in debug mode.
  4. Enter valid email and invalid password and hit submit.
  5. Debug the method and observe that it throws PlatformException, as shown in screenshots above.
flutter doctor -v
[] Flutter (Channel stable, 1.20.3, on Mac OS X 10.15.2 19C57, locale en-US)
     Flutter version 1.20.3 at
     Framework revision 216dee60c0 (8 days ago), 2020-09-01 12:24:47 -0700
     Engine revision d1bc06f032
     Dart version 2.9.2

[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
     Android SDK at /Users/deeptibelsare/Library/Android/sdk
     Platform android-30, build-tools 29.0.3
     ANDROID_HOME = /Users/deeptibelsare/Library/Android/sdk
     ANDROID_SDK_ROOT = /Users/deeptibelsare/Library/Android/sdk
     Java binary at: /Applications/Android
     Java version OpenJDK Runtime Environment (build
     Android license status unknown.
      Try re-installing or updating your Android SDK Manager.
      See or visit for
      detailed instructions.

[] Xcode - develop for iOS and macOS (Xcode 11.6)
     Xcode at /Applications/
     Xcode 11.6, Build version 11E708
     CocoaPods version 1.9.3

[] Android Studio (version 3.6)
     Android Studio at /Applications/Android
     Flutter plugin version 45.1.1
     Dart plugin version 192.7761
     Java version OpenJDK Runtime Environment (build

[] Connected device (2 available)            
     SM A260G (mobile)          5200763ebcfa861f                         
      android-arm  Android 8.1.0 (API 27)
     Darshan's iphone (mobile) • 21150b119064aecc249dfcfe05e259197461ce23 • ios
       iOS 13.6

! Doctor found issues in 1 category.

Other Answers:

Ok managed to replicate and "fix".

flutter/flutter#33427 pretty much sums up the overall issue (news to me!). Basically the .catchError statements within a try/catch aren't seen as a parent exception handler to the IDE so although Dart actually catches the error and deals with it (the reason why using the code without debugging works), the IDE kicks up a fuss.

I just converted everything to try/catch, and explicitly throw an exception.

Need to sort for the other plugins but if anyone can test my PR via pubspec git hash please do!

Related Issues:

flutterfire [firebase_core_web , firebase_auth_web, cloud_firestore_web ] Plugin project :firebase_auth_web not found. Please update settings.gradle.
Hi @gsusI Please add this in flutter app -> android -> settings.gradle if you disagree please write ...
flutterfire [FIREBASE_AUTH] 'UserAgent.h' file not found flutter firebase iOS
I changed dependencies try this Don't use ^ in version. I am working on flutter application with fir...
flutterfire [firebase_messaging] <Background push notification handling - no implementation found for method FcmDartService#initialized>
So in the new firebase_messaging version support for background messages was added Actually if you d...
flutterfire [firebase_auth] iOS verifyPhoneNumber Token mismatch
Same problem with firebase_auth: 0.15.5+3: on the simulator I get the CAPTCHA code and it works ...
flutterfire [firebase_auth] iOS doesn't build when upgrade to 1.15.x
I fixed this temporarily by running pod update in ios folder Describe the bug Flutter app doesn't bu...
flutterfire 🐛 [firebase_auth] Incompatible with latest flutter_localizations master channel.
For now you can simply add the following to your pubspec.yaml if you need to stay on dev channel and...
flutterfire [cloud_firestore] no visible @interface for 'FIRQuery' declares the selector ...
cd ios and run pod update Firebase/Firestore and run build command let me know ...
flutterfire [firebase_messaging] Application.kt: Type mismatch: inferred type is PluginRegistry but FlutterEngine was expected
There is a workaround mentioned in: #1613 Replace: To: Also temporary downgrade firebase_messaging t...
flutterfire Firebase messaging onResume and onMessage broken on iOS since Flutter 1.7.4
everybody: What would be possible other implications when removing that code? Removing those lines m...
flutterfire [firebase_auth] Method swizzling problem with phone auth iOS
@cielo Hi Yes i did I got Token mismatch too But when i fixed AppDelegate.swift i solved this error ...
flutterfire [firebase_admob 0.11.0+1] XCode Build Fails: Google-Mobile-Ads-SDK-fjgkwjemgangjofelixrcilvndtg
Hey guys I think this is because AdMob recently updated their SDK to 8.0.0(because of this firebase_...
flutterfire [firebase_messaging] Type mismatch: inferred type is PluginRegistry? but FlutterEngine was expected
Fixed by replace with: Following the instructions on for handling background messages doesn'...
flutterfire [firebase_messaging] Android v2 embedding crashes
Why is this not labelled severe? This causes crash dialogs to show periodically when the application...
flutterfire 🐛 [firebase_messaging][firebase_auth] Data-only messages not received in iOS. Never fires anything in onMessage
Disabling method swizzling and using the below in my AppDelegate.swift Bug report Describe the bug O...
flutterfire 🐛 [firebase_remote_config: 0.4.1] Plugin using removed method, causing app to crash
Fixed for me by using implementation platform('') instead of impleme...
flutterfire [firebase_messaging] The application cannot be created when I add the
Hi I want to use firebase notifications in my application I'm adding for this After ...
flutterfire 🐛 [Crashlytics] iOS build crashes when adding crashlytics
@kuromukira Workaround for Flutter 2.0.4 is to use firebase_crashlytics from git instead of ...
flutterfire [Cloud Firestore] fatal error: module 'cloud_firestore' not found
I think I managed to workaround the issue I got this error as well after integrating cocoapods mysel...
flutterfire Warnings from the cloud_firestore plugin on Android: uses unchecked or unsafe operations
set: multiDexEnabled true solved for me project/android/app/build.gradle: Steps to Reproduce Create ...
flutterfire firebase-messaging: Android Integration
@OliverWangWei Sorry.. It was a mistake to edit the file Android Integration I'm not...
flutterfire [firebase_crashlytics] Either the Crashlytics plugin doesn't work, or the instruction is wrong
Having the same issue even with a really simple app: I followed the setup instruction from Pub: http...
flutterfire 🐛 [firebase_core] java.lang.IllegalArgumentException: Service not registered:
I get the same error as @kw2019ltd : I get it in a new created flutter project with the only depende...
flutterfire [firebase_messaging] version 6.0.7 brokes builds
I solved it. Adding the plugin dependencies in app/build.gradle My project cannot be built or runned...
flutterfire [all] Flutter Android build fails with firebase dependencies.
Hey @erluxman I am using Android Studio 3.5 stable java -version 1.8 and this is the issue : I have ...
flutterfire [cloud_firestore] INTERNAL ASSERTION FAILED: A transaction object cannot be used after its update callback has been invoked.
Tracked this down to Firebase offline use and Transactions Describe the bug App crash when adding ne...
flutterfire [firebase_admob] ads invades safe area and close button is blocked on iPhone X
Having the same problem Temporary solution: Hide status bar when ads are shown Hope this issue will ...
flutterfire [firebase_messaging] iOS notification onResume, onLaunch callback not working
@AlexandreRoba @SandyAra same issue exists or your comment solution working fine on firebase_messagi...
flutterfire [firebase_messaging] No documentation for Android v2 embedding backgroundMessage handler
Solved it with following: app/src/build.gradle add the following: implementation
flutterfire Unable to use onBackgroundMessage in Firebase Cloud Messaging
Finally I got something working! I ended up using a named ReceivePort I am trying to implement an ap...
flutterfire 🐛 [CLOUD_FIRESTORE] The service is currently unavailable.
Keeps happening...!! what is going on ? Bug report I'm try to use Firestore with Flutter Deskop (Mac...
flutterfire [firebase_in_app_messaging] Can't build for iOS after adding firebase_in_app_messaging
I found out how to fix this Initially Describe the bug The XCode build fails when it's processing th...
flutterfire 🐛 [firebase_messaging] iOS Notifications not received in 8.0.0-dev.8
I'm afraid to say that iOS is still completely dead for me on dev.9 Bug report Describe the bug Afte...
flutterfire 🐛 [Firebase_auth] Not persisting user on authStateChanges stream after 1.1.2
I agree with @budo385 My app was working fine with firebase_auth 1.1.0 version ...
flutterfire [firebase_auth] The reload() function on a FirebaseUser doesn't seem to be working.
Please fix this Hey when calling the .reload() function on a FirebaseUser nothing seems to happen ...
flutterfire 🐛 [firebase_crashlytics] Failed to retrieve settings from
May be it's a 24 hours patience game or try the solution below: Few changes made were: Add implement...
flutterfire [<Firebase_Auth>] Unhandled Platform Exception Before Able to Catch SignInWithEmailAndPassword FirebaseAuthException
I am able to replicate this issue on latest stable (1.20.3) while debugging signInWithEmailAndPasswo...
flutterfire [Firebase Messaging] onBackgroundMessage Never Called
this is how i have created a Notification Handler Class I followed the tutorial on how to add the li...
flutterfire [firebase_messaging] firebase_messaging plugin causing build error in android
@DagobertDokate comment out firebase_messaging: ^5.1.5 run flutter pub get then add firebase_messagi...
flutterfire Flutter heads up notification for Android
@abdallahshaban557 @vipinnegi90 For Now use flutter_local_notification to create a notification chan...
flutterfire 🐛 [Firebase_Auth] Auth Blocking iOS firebase_messaging dev callbacks
Have the same problem on iOS 😕 Bug report Describe the bug didReceiveRemoteNotification is used in ...
flutterfire 🐛 [firebase_messaging] Can't use 3rd party plugins in background handler
@asmodeoux @markusaksli-nc Allright I'm back with a workaround Bug report Describe the bug None of 3...
flutter Multiple commands produce '/build/ios/Debug-iphonesimulator/
I was able to fix it by opening the Runner workspace project in Xcode 10 Then navigate to File ...
flutter App Store iOS submission fails: The bundle does not support the minimum OS Version specified in the Info.plist
After doing a flutter clean changing MinimumOSVersion (inside /ios/Flutter/AppframeworkInfo.plist) t...
flutter '' has different version for the compile (26.1.0) and runtime (27.0.1) classpath
is like this i receive an error when i run flutter run My file is: flutter doctor: ...
flutter Why does my text not wrap?
You have to wrap Column in a flexible Without flexible the column's width is not constrained to the ...
flutter Unexpected top padding in ListView put inside scaffold with no appBar
Yeah this is intentional If you put a widget before the ListView you should wrap the ListView with a...