I'm following a Room tutorial for Kotlin and (at about 40 minutes) I get the following error:
Below is my code (I checked it and it seems exactly how shown in the video)
@Composable
fun AddContactDialog(
state: ContactState,
onEvent: (ContactEvent) -> Unit,
modifier: Modifier = Modifier
){
AlertDialog(
modifier = modifier,
onDismissRequest = {
onEvent(ContactEvent.HideDialog)
},
title = { Text(text = "Add contact") },
text = {
Column(
verticalArrangement = Arrangement.spacedBy(8.dp)
){
TextField(
value = state.firstName,
onValueChange = {
onEvent(ContactEvent.SetFirstName(it))
},
placeholder = {
Text(text = "First Name")
}
)
TextField(
value = state.lastName,
onValueChange = {
onEvent(ContactEvent.SetLastName(it))
},
placeholder = {
Text(text = "Last Name")
}
)
TextField(
value = state.phoneNumber,
onValueChange = {
onEvent(ContactEvent.SetPhoneNumber(it))
},
placeholder = {
Text(text = "Phone Number")
}
)
}
},
buttons = {
Box(
modifier = Modifier.fillMaxWidth(),
contentAlignment = Alignment.CenterEnd
){
Button(onClick = {
onEvent(ContactEvent.SaveContact)
}){
Text(text = "Save")
}
}
}
)
}
Here are my imports:
import androidx.appcompat.app.AlertDialog
import androidxpose.foundation.layout.Arrangement
import androidxpose.foundation.layout.Box
import androidxpose.foundation.layout.Column
import androidxpose.foundation.layout.fillMaxWidth
import androidxpose.material3.Button
import androidxpose.material3.ExperimentalMaterial3Api
import androidxpose.material3.Text
import androidxpose.material3.TextField
import androidxpose.runtime.Composable
import androidxpose.ui.Alignment
import androidxpose.ui.Modifier
import androidx.room.util.TableInfo
import androidxpose.ui.unit.dp
I'm following a Room tutorial for Kotlin and (at about 40 minutes) I get the following error:
Below is my code (I checked it and it seems exactly how shown in the video)
@Composable
fun AddContactDialog(
state: ContactState,
onEvent: (ContactEvent) -> Unit,
modifier: Modifier = Modifier
){
AlertDialog(
modifier = modifier,
onDismissRequest = {
onEvent(ContactEvent.HideDialog)
},
title = { Text(text = "Add contact") },
text = {
Column(
verticalArrangement = Arrangement.spacedBy(8.dp)
){
TextField(
value = state.firstName,
onValueChange = {
onEvent(ContactEvent.SetFirstName(it))
},
placeholder = {
Text(text = "First Name")
}
)
TextField(
value = state.lastName,
onValueChange = {
onEvent(ContactEvent.SetLastName(it))
},
placeholder = {
Text(text = "Last Name")
}
)
TextField(
value = state.phoneNumber,
onValueChange = {
onEvent(ContactEvent.SetPhoneNumber(it))
},
placeholder = {
Text(text = "Phone Number")
}
)
}
},
buttons = {
Box(
modifier = Modifier.fillMaxWidth(),
contentAlignment = Alignment.CenterEnd
){
Button(onClick = {
onEvent(ContactEvent.SaveContact)
}){
Text(text = "Save")
}
}
}
)
}
Here are my imports:
import androidx.appcompat.app.AlertDialog
import androidxpose.foundation.layout.Arrangement
import androidxpose.foundation.layout.Box
import androidxpose.foundation.layout.Column
import androidxpose.foundation.layout.fillMaxWidth
import androidxpose.material3.Button
import androidxpose.material3.ExperimentalMaterial3Api
import androidxpose.material3.Text
import androidxpose.material3.TextField
import androidxpose.runtime.Composable
import androidxpose.ui.Alignment
import androidxpose.ui.Modifier
import androidx.room.util.TableInfo
import androidxpose.ui.unit.dp
Share
Improve this question
edited Nov 20, 2024 at 17:58
genespos
asked Nov 20, 2024 at 16:52
genesposgenespos
3,3116 gold badges43 silver badges76 bronze badges
1 Answer
Reset to default 5androidx.appcompat.app.AlertDialog
is not the correct import, AlertDialog is a composable and is imported like this:
import androidxpose.material3.AlertDialog
There are now multiple AlertDialog composables available (one is deprecated), but none that matches the parameters you provided. The one you want needs a confirmButton
parameter instead of the buttons
parameter. Just rename the parameter accordingly and everything should work fine.