admin管理员组文章数量:1332984
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.
本文标签: androidUnable to get correct import for AlertDialog (Or deprecated import)Stack Overflow
版权声明:本文标题:android - Unable to get correct import for AlertDialog (Or deprecated import?) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742343541a2457065.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论