java.lang.IllegalArgumentException: Service not registered Flutter and Firebase Google SignIn

Viewed 1319

I want to allow sign in with google in my app using Firebase. This is my code:

import 'package:PixiCall/models/user.dart';
import 'package:PixiCall/utils/utilities.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';

class FirebaseMethods {
  final FirebaseAuth _auth = FirebaseAuth.instance;

  GoogleSignIn _googleSignIn = GoogleSignIn();
  static final FirebaseFirestore firestore = FirebaseFirestore.instance;

  //user class
  User1 user = User1();

  Future<User> getCurrentUser() async {
    User currentUser;
    currentUser = await _auth.currentUser;
    return currentUser;
  }

  Future<User> signIn() async {
    GoogleSignInAccount _signInAccount = await _googleSignIn.signIn();
    GoogleSignInAuthentication _signInAuthentication =
        await _signInAccount.authentication;

    final AuthCredential credential = GoogleAuthProvider.credential(
      accessToken: _signInAuthentication.accessToken,
      idToken: _signInAuthentication.idToken,
    );

    User user = (await _auth.signInWithCredential(credential)).user;
    return user;
  }

  Future<bool> authenicateUser(User user) async {
    QuerySnapshot result = await firestore
        .collection('users')
        .where('email', isEqualTo: user.email)
        .get();

    final List<DocumentSnapshot> docs = result.docs;

    //if user is registered then length of list > 0 or else less than 0
    return docs.length == 0 ? true : false;
  }

  Future<void> addDataToDb(User currentUser) async {
    String username = Utils.getUsername(currentUser.email);

    user = User1(
        uid: currentUser.uid,
        email: currentUser.email,
        name: currentUser.displayName,
        profilePhoto: currentUser.photoURL,
        username: username);

    firestore.collection('users').doc(currentUser.uid).set(user.toMap(user));
  }
}

And there is no mistake in VS Code, I have this message in the Terminal when I run the app:

/ConnectionTracker(14606): Exception thrown while unbinding
W/ConnectionTracker(14606): java.lang.IllegalArgumentException: Service not registered: lv@b068d66
W/ConnectionTracker(14606):     at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1484)
W/ConnectionTracker(14606):     at android.app.ContextImpl.unbindService(ContextImpl.java:1638)
W/ConnectionTracker(14606):     at android.content.ContextWrapper.unbindService(ContextWrapper.java:703)
W/ConnectionTracker(14606):     at ci.f(:com.google.android.gms.dynamite_measurementdynamite@204516052@20.45.16 (040700-0):1)
W/ConnectionTracker(14606):     at ci.d(:com.google.android.gms.dynamite_measurementdynamite@204516052@20.45.16 (040700-0):2)
W/ConnectionTracker(14606):     at lw.E(:com.google.android.gms.dynamite_measurementdynamite@204516052@20.45.16 (040700-0):9)
W/ConnectionTracker(14606):     at lg.a(:com.google.android.gms.dynamite_measurementdynamite@204516052@20.45.16 (040700-0):3)
W/ConnectionTracker(14606):     at eg.run(:com.google.android.gms.dynamite_measurementdynamite@204516052@20.45.16 (040700-0):3)
W/ConnectionTracker(14606):     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
W/ConnectionTracker(14606):     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/ConnectionTracker(14606):     at iz.run(:com.google.android.gms.dynamite_measurementdynamite@204516052@20.45.16 (040700-0):5)

This is the login button:

Widget loginButton() {
    return FlatButton(
      padding: EdgeInsets.all(35),
      child: Text(
        'Login',
        style: TextStyle(
          fontSize: 25,
          fontWeight: FontWeight.w900,
          letterSpacing: 1.2,
        ),
      ),
      onPressed: () => performLogin,
    );
  }

  void performLogin() {
    _repository.signIn().then((User user) {
      if (user != null) {
        authenticateUser(user);
      } else {
        print('There was an error');
      }
    });
  }

Also, in the problems tab in VS Code, I have this error: 'await' applied to 'User', which is not a 'Future'. This Error is connected with the first code I provided.

When I click on the login button, nothing happens. It should offer me to sign in with Google, but it doesn't. Does someone know what could be a problem here?

1 Answers

You don't need to use the async method to call the getCurrentUser().

  User getCurrentUser() {
    User currentUser;
    currentUser = _auth.currentUser;
    return currentUser;
  }
Related