Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Firebase Auth / Google Sign in runtime type errors

[UPDATED]: Split the code into 2 functions as suggested by @Ashton to make things a bit simpler. I am a noob with flutter and I am trying to do some really simple things with flutter i.e. building a login page with either firebase login or google login. I face errors with both and I am not able to find out what the reason is for it.

I have firebase setup and my GoogleServices-Info.plist file setup for ios development. The function doing the authentication for me as below.

Future<Null> _googleSignIn() async {
  GoogleSignInAccount user = googleSignIn.currentUser;
  if (user == null)
    user = await googleSignIn.signInSilently();
  if (user == null) {
    user = await googleSignIn.signIn();
  }

  return user;
}

If I use the Google Sign in then I get the following error.

[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
type '_Future' is not a subtype of type 'Future<Null>' where
  _Future is from dart:async
  Future is from dart:async
  Null is from dart:core

#0      GoogleSignIn._callMethod (package:google_sign_in/google_sign_in.dart)
<asynchronous suspension>
#1      GoogleSignIn._addMethodCall.<anonymous closure> (package:google_sign_in/google_sign_in.dart:196:28)
#2      _RootZone.run (dart:async/zone.dart:1376:54)
#3      _FutureListener.handleWhenComplete (dart:async/future_impl.dart:151:18)
#4      _Future._propagateToListeners.handleWhenCompleteCallback (dart:async/future_impl.dart:603:39)
#5      _Future._propagateToListeners (dart:async/future_impl.dart:659:37)
#6      _Future._addListener.<anonymous closure> (dart:async/future_impl.dart:342:9)
#7      _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#8      _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

However, if I call the firebase simple auth system, then if the user doesn't exist and I try to use the createUserWithEmailAndPassword then the following error comes back.

Future<Null> _firebaseAuthSignIn(String email, String password) async {
  FirebaseUser firebaseUser;
  try {
    firebaseUser = await auth.signInWithEmailAndPassword(
        email: email, password: password);
    final userid = FirebaseAuth.instance.currentUser;
  } catch (exception) {
    firebaseUser = await auth.createUserWithEmailAndPassword(
        email: email, password: password);
  }

  return firebaseUser;
}

Although, this creates the user in firebase, the function createUserWithEmailAndPassword causes the exception below..

[VERBOSE-2:dart_error.cc(16)] Unhandled exception:
type '_InternalLinkedHashMap' is not a subtype of type 'Map<String, dynamic>' where
  _InternalLinkedHashMap is from dart:collection
  Map is from dart:core
  String is from dart:core

#0      FirebaseAuth.createUserWithEmailAndPassword (package:firebase_auth/firebase_auth.dart)
<asynchronous suspension>
#1      _ensureLoggedIn (package:remy/auth/login.dart:28:41)
<asynchronous suspension>
#2      LoginPageState._handleSubmit (package:remy/auth/login.dart:64:11)
<asynchronous suspension>
#3      LoginPageState.build.<anonymous closure> (package:remy/auth/login.dart:132:41)
#4      _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:478:14)
#5      _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:530:30)
#6      GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
#7      TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:161:9)
#8      TapG<…>

My initial reaction was that since these errors look like type inconsistencies, the package versions were not latest. However, I double checked and my versions are upto date..

google_sign_in: 3.0.0 firebase_auth: 0.5.1

Any help in the right direction would be really helpful. Thanks

like image 246
ssarangi Avatar asked May 01 '26 22:05

ssarangi


1 Answers

I ran into this also.

I think this might be a bug in version 3.0. I downgraded to 2.1.2

e.g.

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  # ...
  google_sign_in: 2.1.2

And the issue disappear

like image 109
Kyle Finley Avatar answered May 03 '26 16:05

Kyle Finley