Flutter firebase stream restart crash

Viewed 207

I have a problem with stream and firebase, when the app starts the first time everything works correctly, when I try to do a restart the app closes with this error and I can't understand why. the problem is the stream if I remove the stream the forced reload works correctly

StreamBuilder(
        stream: FirebaseAuth.instance.userChanges(),
        builder: (ctx, userSnapshot) {
          if (userSnapshot.connectionState == ConnectionState.waiting) {
            print("SPLASH");
            return SplashScreen();
          } else if (userSnapshot.hasData) {
            return WelcomeScreen();
          } else {
            print("WELCOME");
            return WelcomeScreen();
          }
        });



Restarted application in 658ms.
-[__NSCFString setStreamHandler:]: unrecognized selector sent to instance 0x283512620
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString setStreamHandler:]: unrecognized selector sent to instance 0x283512620'
*** First throw call stack:
(0x19c5e586c 0x1b15fec50 0x19c4ec95c 0x19c5e8438 0x19c5ea740 0x1045f56d4 0x1045f7af0 0x104606c88 0x1046049ac 0x104603928 0x1053f0694 0x104b90038 0x104e8f41c 0x104e2e81c 0x104e30ed4 0x19c561fa0 0x19c561ba0 0x19c560ffc 0x19c55aee4 0x19c55a21c 0x1b4124784 0x19ef9aee8 0x19efa075c 0x1045f44b0 0x19c21a6b0)
libc++abi.dylib: terminating with uncaught exception of type NSException
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x00000001ca535414 libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`__pthread_kill:
->  0x1ca535414 <+8>:  b.lo   0x1ca535434               ; <+40>
    0x1ca535418 <+12>: pacibsp
    0x1ca53541c <+16>: stp    x29, x30, [sp, #-0x10]!
    0x1ca535420 <+20>: mov    x29, sp
Target 0: (Runner) stopped.
2 Answers

As stated in this Issue you could either revert

firebase_auth

to ^1.1.2 or follow the steps provided in this issue.

But just reverting to 1.1.1 fixed the issue for me!

Make sure that you have your dependencies like this:

firebase_auth: 1.1.1

Crash is gone for me with patched -[FLTFirebaseAuthPlugin cleanupWithCompletion:] method:


- (void)cleanupWithCompletion:(void (^)(void))completion {
  // Cleanup credentials.
  [_credentials removeAllObjects];

  for (FlutterEventChannel *channel in self->_eventChannels.allValues) {
    [channel setStreamHandler:nil];
  }
  [self->_eventChannels removeAllObjects];
  for (NSObject<FlutterStreamHandler> *handler in self->_streamHandlers.allValues) {
    [handler onCancelWithArguments:nil];
  }
  [self->_streamHandlers removeAllObjects];

  if (completion != nil) completion();
}

The original issue is caused by for..in loop that was iterated over dictionary keys but uses them as values.

Related