title: Flutter Google Sign In - Email data returns null
body: <p>Flutter Google Sign In - Email data returns null. Logs are given below. Thank you very much in advance.</p>
  
  <p><strong>I use Firebase.</strong></p>
  
  <p><strong>I want to login with Google, but</strong> <code>AuthResult.user.email == null</code></p>
  
  <p><strong><em>------------------------Log error----------------------------</em></strong> </p>
  
  <pre><code>D/FirebaseAuth( 5302): Notifying id token listeners about user ( 9uKLCYS4VwUbuu77KS27bWjKrlI2 ).
  I/flutter ( 5302): Result : Poyraz Çakmak https://lh3.googleusercontent.com/a-/AAuE7mABS7DqwgoIHuFfIwNw_574FRdvxKuvVyNarFo0_w=s96-c null
  I/flutter ( 5302): NoSuchMethodError: The method 'indexOf' was called on null.
  I/flutter ( 5302): Receiver: null
  I/flutter ( 5302): Tried calling: indexOf("@")
  </code></pre>
  
  <p><strong>because User model from userName format. =>  Tried calling: indexOf("@")</strong> </p>
  
  <p><strong>GoogleSignIn method:</strong></p>
  
  <pre><code>@override
  Future&lt;User&gt; login() async {
  final GoogleSignInAccount googleSignInAccount =
      await MyToolsFirebase.googleSignIn.signIn();
  
  if (googleSignInAccount != null) {
    GoogleSignInAuthentication googleSignInAuthentication =
        await googleSignInAccount.authentication;
  
    final String idToken = googleSignInAuthentication.idToken;
    final String accessToken = googleSignInAuthentication.accessToken;
  
    if (idToken != null &amp;&amp; accessToken != null) {
      AuthResult authResult = await MyToolsFirebase.firebaseAuth
          .signInWithCredential(GoogleAuthProvider.getCredential(
              idToken: idToken, accessToken: accessToken));
  
      return await MyToolsFirebase.saveDbUser(firebaseUser: authResult.user);
    }
  }
  return null;
  }
  </code></pre>
  
  <p><strong>MyToolsFirebase class:</strong></p>
  
  <pre><code>import 'package:cloud_firestore/cloud_firestore.dart';
  import 'package:firebase_auth/firebase_auth.dart';
  import 'package:google_sign_in/google_sign_in.dart';
  import 'package:live_chat/Models/User.dart';
  
  class MyToolsFirebase {
  
    static final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
  
    static final GoogleSignIn googleSignIn = GoogleSignIn(
      scopes: &lt;String&gt;[
        'https://www.googleapis.com/auth/contacts.readonly',
        'https://www.googleapis.com/auth/plus.login',
        'https://www.googleapis.com/auth/userinfo.email'
      ],
    );
  
    static final Firestore firestore = Firestore.instance;
  
    static User userFromFirebaseUser({@required FirebaseUser firebaseUser}) {
      if (firebaseUser == null) return null;
      print("Result : ${firebaseUser.displayName} ${firebaseUser.photoUrl} ${firebaseUser.email}");
      return User(
        uid: firebaseUser.uid,
        email: firebaseUser.email,
        name: firebaseUser.displayName,
        imageURL: firebaseUser.photoUrl,
      );
    }
  
  
    static Future&lt;User&gt; saveDbUser({@required FirebaseUser firebaseUser}) async {
      User user = userFromFirebaseUser(firebaseUser: firebaseUser);
      Map userMap = user.toMap();
  
      await firestore.collection("users").document(user.uid).setData(userMap);
      return await getDbUser(user.uid);
    }
  
    static Future&lt;User&gt; getDbUser(String uid) async {
      DocumentSnapshot documentSnapshot = await Firestore.instance.collection("users").document(uid).get();
      print(User.fromMap(documentSnapshot.data).toString());
      return User.fromMap(documentSnapshot.data);
    }
  }
  </code></pre>
  
  <p><strong>User model:</strong></p>
  
  <pre><code>class User {
    final String uid;
    String email;
    String userName;
    String name;
    String imageURL;
    int level;
    DateTime createdAt;
    DateTime updatedAt;
  
    User({
      @required this.uid,
      @required this.email,
      this.userName,
      this.name,
      this.imageURL,
      this.level,
      this.createdAt,
      this.updatedAt,
    });
  
    User.fromMap(Map&lt;String, dynamic&gt; map)
        : this.uid = map["uid"],
          this.email = map["email"],
          this.userName = map["userName"],
          this.name = map["name"],
          this.imageURL = map["imageURL"],
          this.level = int.parse(map["level"]),
          this.createdAt = (map["createdAt"] as Timestamp).toDate(),
          this.updatedAt = (map["updatedAt"] as Timestamp).toDate();
  
    Map&lt;String, dynamic&gt; toMap() {
      DateTime now = DateTime.now().toLocal().toUtc();
      return {
        'uid': this.uid,
        'email': this.email,
        'userName': this.userName ?? this.email.substring(0, this.email.indexOf("@")) + Random().nextInt(1000).toString(),
        'name': this.name,
        'imageURL': this.imageURL ?? "https://www.logolynx.com/images/logolynx/61/61ba01858af7f2ea1184238e9f2771f2.png",
        'level': this.level ?? 1,
        'createdAt': this.createdAt ?? now,
        'updatedAt': this.updatedAt ?? now,
      };
    }
  }
  </code></pre>