@Composable
fun loginButton(loginType: Int, context: Context, googleSignInClient: GoogleSignInClient?) {
Column(horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.fillMaxWidth()) {
if (loginType == 0) {
OutlinedButton(onClick = {
googleSignIn(context = context, googleSignInClient = googleSignInClient)
}, border = BorderStroke(2.dp, Color.Black), colors = ButtonDefaults.buttonColors(backgroundColor = Color(0xFFFFFFFF)), modifier = Modifier
.height(40.dp)
.width(300.dp), shape = RoundedCornerShape(50)
) {
Image(painter = painterResource(id = R.drawable.google_logo), contentDescription = "Google Logo(Src: Wikipedia)")
Spacer(modifier = Modifier.width(30.dp))
Text(text = "Sign in with Google", fontSize = 15.sp, color = Color.Black)
}
} else if (loginType == 1) {
OutlinedButton(onClick = {
}, border = BorderStroke(2.dp, Color.Black), colors = ButtonDefaults.buttonColors(backgroundColor = Color(0xFFFFFFFF)), modifier = Modifier
.height(40.dp)
.width(300.dp), shape = RoundedCornerShape(50)
) {
Image(painter = painterResource(id = R.drawable.apple_logo), contentDescription = "Google Logo(Src: Wikipedia)")
Spacer(modifier = Modifier.width(30.dp))
Text(text = "Sign in with Apple", fontSize = 15.sp, color = Color.Black)
}
} else {
Text("Cannot load the sign in button")
}
}
}
You can see googleSignIn() from the 6th line which caused that error. That is the function in other Kotlin file. The code for that function is under here.
@Composable
fun googleSignIn(context: Context, googleSignInClient: GoogleSignInClient?) {
val signInLauncher = rememberLauncherForActivityResult(contract = ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
if (result.resultCode == Activity.RESULT_OK) {
val intent = result.data
if (result.data != null) {
val task: Task<GoogleSignInAccount> = GoogleSignIn.getSignedInAccountFromIntent(intent)
try {
val account = task.getResult(ApiException::class.java)
Log.d("AuthManager", "FirebaseAuthWithGoogle" + account.id)
} catch (e: ApiException) {
e.printStackTrace();
Log.w("LoginActivity", "Google sign in failed", e);
}
}
}
}
signInLauncher.launch(googleSignInClient?.signInIntent)
}
I don't know what is the problem. First, I want googleSignIn() at the 6th line of loginButton to work with 'context' at the parameter of loginButton. Second, I want to get this error fixed.