Android 函数必须用 @Composable 标记

发布于 2025-01-15 04:45:22 字数 730 浏览 3 评论 0原文

我有一个 @Composable 函数,可以使用 教程 与内部的单个元素完美配合。但是,通过添加 LocalInspectionMode.current 或其他元素(例如 column),它会产生一个奇怪的错误。

@Composable
fun MessageCard(name: String){
    if(LocalInspectionMode.current){
    Text("Hello $name!")
    } else {
        Text("Goodbye $name!")
    }
}

@Composable
fun MessageCard(msg: Message){
    Column {
        Text("Hello ${msg.author}!")
        Text("Hello ${msg.author}!")
    }
}

错误消息:

调用 @Composable 函数的函数必须用 @Composable注解

显然,该函数确实包含 @Composable 注解。 有什么帮助吗?谢谢

I have a @Composable function that works perfectly with single element inside using the tutorial. However, by adding LocalInspectionMode.current or other elements, such as, column, it produces a strange error.

@Composable
fun MessageCard(name: String){
    if(LocalInspectionMode.current){
    Text("Hello $name!")
    } else {
        Text("Goodbye $name!")
    }
}

or

@Composable
fun MessageCard(msg: Message){
    Column {
        Text("Hello ${msg.author}!")
        Text("Hello ${msg.author}!")
    }
}

The error message:

Functions which invoke @Composable functions must be marked with the
@Composable annotation

Obviously, the function does contain the @Composable annotation.
Any help? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文