Get user's birthday/gender using Google Sign-In in Flutter Get user's birthday/gender using Google Sign-In in Flutter dart dart

Get user's birthday/gender using Google Sign-In in Flutter


I hope this becomes useful to anyone else facing the same trouble :)

 GoogleSignIn googleSignIn = GoogleSignIn(scopes: ['email',"https://www.googleapis.com/auth/userinfo.profile"]);    @override  Future<User> login() async {    await googleSignIn.signIn();    User user = new User(      email: googleSignIn.currentUser.email,      name: googleSignIn.currentUser.displayName,      profilePicURL: googleSignIn.currentUser.photoUrl,      gender: await getGender()    );         return user;  }  Future<String> getGender() async {    final headers = await googleSignIn.currentUser.authHeaders;    final r = await http.get("https://people.googleapis.com/v1/people/me?personFields=genders&key=",      headers: {        "Authorization": headers["Authorization"]      }    );    final response = JSON.jsonDecode(r.body);    return response["genders"][0]["formattedValue"];  }