无法导入以修复“onClick”无法识别的错误

问题描述 投票:0回答:1

我是 Kotlin 新手,正在学习 Room 教程,但是(大约 32 分钟时)我收到一个无法修复的错误:

enter image description here

这是我的代码:

@Composable
fun ContactScreen(
    state: ContactState,
    onEvent: (ContactEvent) -> Unit
){
    Scaffold(
        floatingActionButton = {
            FloatingActionButton(onClick ={
                onEvent(ContactEvent.ShowDialog)
            }){
                Icon(imageVector = Icons.Default.Add, contentDescription = "Add contact")
            }

        }
    ){padding ->
        LazyColumn (
            contentPadding = padding,
            modifier = Modifier.fillMaxSize(),
            verticalArrangement = Arrangement.spacedBy(16.dp)
        ){

        }
    }
}

这些是我的进口:

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.google.android.material.floatingactionbutton.FloatingActionButton

这是视频截图(我检查了每个逗号和括号) enter image description here

kotlin onclick
1个回答
0
投票

解决方案在评论里:

您导入了错误的

FloatingActionButton
。应该是
androidx.compose.material3.FloatingActionButton
。 – 迈克·M.

感谢迈克

© www.soinside.com 2019 - 2024. All rights reserved.